-1

I have a UICollectionView somewhat similar to the screenshot as shown, but this image is taken off from the Internet.

In my app, I also have 3 items per row. My problem here is how do I change the gaps between cells. Example, in the screenshot, I want the gap between cell 3 and cell 4 to be 10 pixels, so as cell 3 and cell 6 also 10 pixels.

enter image description here

jo3birdtalk
  • 616
  • 5
  • 20

3 Answers3

0
layout.minimumInteritemSpacing = 0 //add your spacing
layout.minimumLineSpacing = 0 //add your spacing
David Seek
  • 16,783
  • 19
  • 105
  • 136
0

enter image description here

You can add spacing in the interface builder, too. Just click the collection view and on the right the size inspector. You can add spacing at the: MIN SPACING

David Seek
  • 16,783
  • 19
  • 105
  • 136
  • actually I set all of them at 8. But no idea why there are so much spaces in between. – jo3birdtalk Feb 16 '16 at 09:53
  • I'M NOT SURE, but I guess. 8 is a spacing of 16. because every cell has a spacing of 8. so if there are 2 cells, both with spacing of 8 is a total spacing of 16. Have you tryed to minimize that spacing to test it? – David Seek Feb 16 '16 at 09:56
  • yes I did. I think I would need to relook at the whole thing again. – jo3birdtalk Feb 16 '16 at 15:35
0
if you set spacing in collection view through storyboard spacing will be same in all collection view cell so if you want to set different spacing in collection cell you need to work with collection view delegate method ->

 -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
Sabby
  • 403
  • 3
  • 15