I've created what I thought was a basic UICollectionView using xCode 5, iOS 7, Storyboards, AutoLayout OFF, however I'm getting strange results.
I had hoped to create a single "column" - that is, all cells stacked vertically, none side-by-side (like a TableView for example):
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
However, I'm getting 2 columns like this (which I can only see if I scroll horizontally):
| 1 | | 2 |
| 3 | | 4 |
| 5 |
My CollectionView is the same width as my cells, 1 section, no insets, no headers, scroll direction=vertical, layout=Flow.
EDIT: I tried adding 5 cells via the Storyboard and they lined up exactly as I want, but still do not line up when added programatically...
EDIT2: FYI, I also another UICollectionView which works fine - the only difference is that it is 4x4
How can I achieve the 'single column' layout?
Look into implementing -(CGSize)collectionView:layout:sizeForItemAtIndexPath:
of the UICollectionViewDelegateFlowLayout
. You can adjust your cells based on the collection view bounds. The flow layout is currently taking advantage of the fact that 2 of your cells can fit side-by-side while the device is in landscape orientation.
Another approach is to modify the inset for a section (ie, you can pad such that a single column is all you see) using -(UIEdgeInsets)collectionView:layout:insetForSectionAtIndex:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With