自定义collectionviewflowLayout

class CustomFlowLayout: UICollectionViewFlowLayout {
    var attributeArr: [UICollectionViewLayoutAttributes] = []
    var totalHeight: CGFloat = 0
    
    //insetArr(用来没放每组中的上线左右的距离)
    var insetDict: [Int: UIEdgeInsets] = [:]
    var minLineDict: [Int: CGFloat] = [:]
    var minInterDict: [Int: CGFloat] = [:]
    override func prepare() {
        super.prepare()
        guard let collectionView = self.collectionView else { return }
        let sections =  self.collectionView?.numberOfSections ?? 0
        ///左边距离的位置
        var leftWidth: CGFloat = 0
        var superWidth: CGFloat = collectionView.bounds.width
        var leaveWidth: CGFloat = superWidth
        for indexPathSection in 0.. [UICollectionViewLayoutAttributes]? {
        return self.attributeArr
    }
    
    
//    override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
//        return true
//    }
    override var collectionViewContentSize: CGSize{
        get {
            return CGSize.init(width: self.collectionView?.bounds.width ?? 0, height: self.totalHeight)
        }
    }
    
}

你可能感兴趣的:(自定义collectionviewflowLayout)