I'm trying to achieve Pinterest layout in my app
and I used the following delegate method to achieve that and set the cell height dynamically
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) // Added 120 for a description I will add later
}
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 white spaces which I don't know how to remove.
How can I fix this?