Two UICollectionView columns with a header

I have a layout that has two columns side by side. Is there an easy way to do this using a single UICollectionView? The only requirement is that the solution should work for iOS 8, and the cells should be arranged vertically in each column as follows:

----------------- | A | | B | ----------------- | C | E | | C | F | | D | | | E | | ----------------- 

The folded Cs demonstrate that the cells in the left and right columns can be of different heights, so this is not enough to just draw them on the left, right, left, right.

+7
uicollectionview uicollectionviewcell uicollectionviewlayout uicollectionreusableview
source share
1 answer

This is actually quite simple using a UICollectionView layout UICollectionView . Since each cell can have a dynamic height, the only thing you need is that each cell has a width of 160 (or half the width of the collection view). Then we implement collectionView:layout:sizeForItemAtIndexPath: so that each element can return its corresponding height.

Since each cell has a dynamic height, you can get one column much longer than the other. If you also want an equal column height, then you will want to shuffle the order of your list so that the height for the first half of the items is about half the other half.

enter image description here

+2
source share

All Articles