iOS - UICollectionView spacing still there when set to 0 - How to set with no spacing between cells

前端 未结 6 1447
南旧
南旧 2020-12-16 12:03

I have a simple UICollectionView which I have set with 0 spacing in InterfaceBuilder but when I populate the collection view with cells there is still some spacing. Is there

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 12:40

    Swift 3 version of @MihirOza 's solution

    Worked for both Horizontal and Vertical collection views

    Code

    // removing spacing
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0.0
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0.0
    }
    

提交回复
热议问题