How to give Space between rows and columns of NSCollectionView?

2.6k views Asked by At

I have created collection view and I am unable to give space between the collection view items. So please help.... Thanks in advance...

I have used this link to create collection view https://andrehoffmann.wordpress.com/2009/08/29/nscollectionview-tutorial-for-dummies-xcode-3-1-3/

2

There are 2 answers

1
Alex Andrews On

If you are using storyboard to create the collection view update the Min Spacing and Section Inset like

enter image description here

1
Ben Gottlieb On

You need to modify the CollectionView's layout. Probably the simplest thing to do is give it a Flow layout, and assign your properties there. Here's an example:

let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 5
layout.sectionInset = EdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
layout.minimumLineSpacing = 8
self.collectionView.collectionViewLayout = layout

If you want to do much more than this with respect to item layout, you'll need to subclass UICollectionViewLayout and override the various layout method.