How to set custom Collection View Cell spacing for every cell

时间:2016-10-15 16:57:21

标签: ios swift uicollectionview cellspacing

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 个答案:

答案 0 :(得分:0)

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.