1

I am trying to make custom cell height. But the next cell is starting from the maxY of previous cell. I want to fill the gap there. How to achieve that ?

This is what I am getting now : enter image description here

Here the 3rd cell is in the vertically centered to 4th cell, but it should be match the minY of 4th cell.

Here is how I am calculating size :

extension SomeController: UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        let spacing: CGFloat = 10
        let smallestWidth = collectionView.bounds.width/3 - spacing

        if indexPath.item % 9 == 0 && indexPath.item != 0 {
            return CGSize(width: collectionView.bounds.width, height: smallestWidth * 2)
        } else if indexPath.item % 4 == 0 && indexPath.item != 0 && indexPath.item % 8 != 0 {
            return CGSize(width: smallestWidth * 2, height: smallestWidth * 2)
        } else {
            return CGSize(width: smallestWidth, height: smallestWidth )
        }
    }
}
Sharad Chauhan
  • 4,821
  • 2
  • 25
  • 50

1 Answers1

0

Take a look at this project, especially UICollectionViewWaterfallLayout.m class

Asif Mujtaba
  • 447
  • 6
  • 17