Reputation: 2734
I'm in tad of a dilemma with an application here.
Id like a CollectionView
to be filled with modules and icons, positioned in the center of the display. I'm able to center the CollectionView
using the AutoLayout helpers, but i cant seem to figure out how to size the items correctly.
Currently, there are 4 items in a row, where as i would like to only have two, ( 50% width ) items in a row.
I figured the itemSize
attribute, and the corresponding CGsize method
, but that is only static pixels ( 120, 300 ) And therefor not representative for what i would like both on large and small devices.
Are there any way to make the items lock at: 2 per. row. 50% width + gutter
Thanks in advance!
Jonas
Upvotes: 0
Views: 1288
Reputation: 1985
Look at UICollectionViewDelegateFlowLayout
protocol, which has datasource methods like
sizeForItemAtIndexPath
minimumInteritemSpacingForSectionAtIndex
return custom values to layout collectionview's cells as you want.
Use collectionView.collectionViewLayout.collectionViewContentSize
to get proper content size. But it will be valid only after collection view completes its layout, so you can just use collectionView's frame instead.
Upvotes: 1