Question

I'd like to have a layout in the collection view with custom sizes for each cell. Because of this, I would like cells to fit nicely together, as you can see here:

Well laid out images

(With the first cell being the top one, then the bottom left being number 2 and bottom right being number 3). The direction of scrolling is horizontal (i.e. left to right).

However, when I implement the custom sizes for each cell, the cells don't fill in white space and instead I end up with a layout similar to this:

Wrong layout

To achieve this result, would I need to subclass UICollectionViewFlowLayout or is there a way of organising the cells to take up as much free space as possible?

Was it helpful?

Solution

You need to implement your own layout, by subclassing UICollectionViewLayout. It's not that complicated. There are tons of examples online.

Here is one using the original Apple example: http://markpospesel.wordpress.com/2012/10/25/fixing-circlelayout/

Another example that looks like what you want to do: https://github.com/chiahsien/CHTCollectionViewWaterfallLayout

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top