0

I am using the UICollectionViewDelegateFlowLayout in my subclassed UICollectionViewController, I am setting the heights of the cells with this:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    
    let cellHeight = arc4random_uniform(100) + 200
    print("cell height: \(cellHeight)")
    return CGSize(width: collectionView.bounds.size.width/2 - 1, height: CGFloat(cellHeight))
  }

And the cells now look like this:

Image

Is there a way I can make the CollectionViewCells have 0 vertical space in between cells? Obviously this would mean the rows are not aligned, so does that make it impossible to do with a Flow layout?

Community
  • 1
  • 1
A_toaster
  • 1,196
  • 3
  • 22
  • 50
  • 1
    I think this is good for you https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest – Bhupat Bheda May 03 '17 at 08:42
  • Check this http://stackoverflow.com/questions/27285258/collectionview-dynamic-cell-height-swift – Ruhi May 03 '17 at 09:28

1 Answers1

0

Use this in viewDidLoad:

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
Vamshi Krishna
  • 979
  • 9
  • 19
  • Unfortunately I did both of these but with `UICollectionViewFlowLayout` delegate methods, but they do not eliiminate the verical spacing between some of the cells – A_toaster May 03 '17 at 18:24