2
votes

I have a simple UICollectionView setup in my storyboard with a prototype cell. I have set all section insets to 10, top, left, bottom and right.

The important bit, I have set the minimum spacing for cells and lines to 5. When I run the app and have for example 2 cells in my collection view, the cells are not aligned left with spacing of 5px between each cell.

Instead, there is a 20px space between each cell, left to right. Why would this be? No matter what I set the spacing to be, it always is 20px.

Any idea why this would be? All I want is my cells to be spaced as I set it, i.e. 5px gaps.

EDIT:

I have thought of a far simpler, and better way of asking. Can I set a maximum cell spacing? Clearly we can set a minimum, but that won't stop the spacing being larger than I want it to.

1
Ever figure this out? - Adam Johns

1 Answers

1
votes

You have to specify the width and height of your cells because your cells won't expand or collapse based on the insets. use the -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPathmethod to size your cells according to your needs.