How to set custom Collection View Cell spacing for every cell

609 views Asked by At

I have a Collection View and I want to calculate the spacing between every single cell programmatically but I can't find out how to do this.

So, how can I calculate the inter-cells spacing between UICollectionViewCells in a UICollectionView with UICollectionViewFlowLayout?

1

There are 1 answers

3
DevKyle On BEST ANSWER

Below is how you set custom cell spacing in a collectionview. You have to create an extension.

extension ViewController : UICollectionViewDelegateFlowLayout {

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

    return //whatever you want//

}

Make sure the "ViewController" that follows extension is the name of your viewcontroller.