Cell spacing in UICollectionView

后端 未结 26 3594
旧巷少年郎
旧巷少年郎 2020-11-22 15:53

How do I set cell spacing in a section of UICollectionView? I know there is a property minimumInteritemSpacing I have set it to 5.0 still the spaci

26条回答
  •  春和景丽
    2020-11-22 16:42

    Swift 3 Version

    Simply create a UICollectionViewFlowLayout subclass and paste this method.

    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
            guard let answer = super.layoutAttributesForElements(in: rect) else { return nil }
    
            for i in 1.. previousAttributes.frame.origin.x) {
                    var frame = currentAttributes.frame
                    frame.origin.x = origin + maximumSpacing
                    currentAttributes.frame = frame
                }
            }
    
            return answer
    }
    

提交回复
热议问题