UICollectionViewFlowLayout minimumInteritemSpacing doesn't work

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 ;)


"line spacing" can mean the space between vertical lines.

Say you have a ordinary single line horizontal collection view.

(Eg, the whole view is simply 50 high, and the items are simply 50x50.)

As user @matt has explained

  • a horizontal collection view has columns of cells

  • the "lines" as Apple means it are the vertical "lines" (!) of cells

Thus:

  • in the case of a simple horizontal collection view with one row,

  • what Apple names the "line" spacing is - indeed - the spacing between items

Thus surprisingly in a simple horizontal collection view with one row, to set the gap between items, it's just:

l.minimumLineSpacing = 6  // Apple means "vertical scan lines" by "lines"

(minimumInteritemSpacing is completely meaningless in a normal simple horizontal collection view with one row.)

This finally explains why there are 100 pages on the internet asking why minimumInteritemSpacing just doesn't work. Fantastic tip by user @matt