Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionViewFlowLayout minimumInteritemSpacing doesn't work

I've got two problems with my UICollectionView:

  • minimumInteritemSpacing doesn't work
  • it overflows horizontally on iOS 6

I set up the layout like this:

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(70.0f, 70.0f);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumLineSpacing = 0.0f;
layout.minimumInteritemSpacing = 0.0f;

_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
// I set the size of _collectionView in layoutSubviews:
// _collectionView.frame = self.bounds;

_collectionView.contentInset = UIEdgeInsetsMake(8.0f, 8.0f, 8.0f, 8.0f);

The image shows the result on iOS 6 (on iOS 7 there is no overflow, but the spacing between columns is still not zero)

enter image description here

I tried this solution https://gist.github.com/OliverLetterer/5583087, but it doesn't fix anything in my case.

like image 272
HiveHicks Avatar asked Jun 19 '14 10:06

HiveHicks


People also ask

What is Minimuminteritemspacing in Swift?

For a vertically scrolling grid, this value represents the minimum spacing between items in the same row. For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column.

What is Uicollectionviewflowlayout?

A layout object that organizes items into a grid with optional header and footer views for each section.


1 Answers

From the documentation for the minimumInterItemSpacing property:

For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column. This spacing is used to compute how many items can fit in a single line, but after the number of items is determined, the actual spacing may possibly be adjusted upward.

The flow layout will evenly space cells across its width, with a spacing of no smaller than the minimum you set. If you don't want the spacing, you'll need to implement your own layout.

The iOS 6 overflow issue I'm not sure about. Try dropping support for iOS 6 ;)

like image 148
jrturton Avatar answered Sep 19 '22 11:09

jrturton