I am trying to achieve Pinterest layout in my application
and for this I used the following delegation method and dynamically set the cell height
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let boundingRect = CGRect(x: 0, y: 0, width: self.view.frame.size.width / 2 - 20, height: CGFloat(MAXFLOAT)) let data = articles[indexPath.row] let rect = AVMakeRect(aspectRatio: (data.coverImage?.size)!, insideRect: boundingRect) return CGSize(width: rect.width, height: rect.height + 120)
But I got the following result:

The gray background is the background of the cell, you can see that each cell has its own height (as expected) but there are extra spaces that I donβt know how to remove.
How can i fix this?
swift pinterest uicollectionviewcell
nouf
source share