mischa-hildebrand / AlignedCollectionViewFlowLayout

A collection view layout that gives you control over the horizontal and vertical alignment of the cells.
MIT License
1.28k stars 202 forks source link

Any way to keep spacing the same and increase item sizes to justify? #17

Closed hipwelljo closed 6 years ago

hipwelljo commented 6 years ago

Thank you for creating this great layout and sharing it with the world! ++ for a very nice readme.

I would like to create a justified layout just like the default settings provide, except instead of increasing the spacing between items, it would increase the width of the cells in that row equally to fill the available width. So the amount of spacing between the items remains consistent and the cells themselves are dynamically sized to fill the space. Would that be possible using this layout?

So given this current layout simulator screen shot - iphone x - 2018-11-01 at 13 12 33

I'm envisioning it would obtain the same amount of spacing in row 4 for rows 1-3 by increasing the width of the cells in each row until that same spacing is obtained.

mischa-hildebrand commented 6 years ago

Hi @hipwelljo, unfortunately, you cannot achieve your desired layout with this library. It's actually quite complex: For that kind of layout, you would need several layout passes:

  1. Layout all cells according to their "intrinsic" size / the size described solely by the cells' constraints.
  2. Compute how many cells fit in each row.
  3. Compute the available free space in each row.
  4. Add that extra space (divided by the number of cells) to each cell in its respective row.
  5. Relayout every cell after changing its size.
  6. Reposition every cell accordingly.

It's possible to do that but if I were to implement that kind of layout, I certainly wouldn't go with a subclass of UICollectionViewFlowLayout...

hipwelljo commented 6 years ago

Thanks for your response!