0

Normally I just use this function:

optional func collectionView(_ collectionView: UICollectionView, 
                      layout collectionViewLayout: UICollectionViewLayout, 
minimumLineSpacingForSectionAt section: Int) -> CGFloat

to set some spacing between the items in a collectionView, but the spacing is the same for all items. I would like to set the spacing to be different between some items, depending on some logic that I need to check, the logic will depend on which cell is before and after, so I would need something like IndexPath to check that.

When we want to set size of a cell, we conveniently get IndexPath from the function below, but not from the function above.

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

What can I do to achieve this?

Alex
  • 5,671
  • 9
  • 41
  • 81

1 Answers1

0

There's no good way to do it without creating your own layout. There's too much to it to go into it here, but there's tons of good tutorials on the matter. Here's a good place to start.

Oscar Apeland
  • 6,422
  • 7
  • 44
  • 92