Based on UICollectionViewFlowLayout, implementing a support section more waterfalls flow component

Recently, due to the requirements of the project, a multi-section waterfall flow implementation component was written, which is completely based on SWIFT 5. First, take a look at the renderings directly:

I sorted it out a little bit and made it as simple and quick as possible.

1. Initialization

Based on UICollectionViewFlowLayout implementation. As a result, the flowLayout initialization call with process and system, only need to follow WaterfallMutiSectionDelegate agent.

let layout = WaterfallMutiSectionFlowLayout()
layout.delegate = self
let collection = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout)
Copy the code

2. Proxy implementation

2.1 Proxy methods must be implemented

Func heightForRowAtIndexPath(collectionView Collection: UICollectionView, Layout: WaterfallMutiSectionFlowLayout, indexPath: IndexPath, itemWidth: CGFloat) -> CGFloatCopy the code

2.2 Optional implementation of proxy methods

@objc optional func columnNumber(collectionView Collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: @objc optional func referenceSizeForHeader(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGSize @objc optional func referenceSizeForFooter(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGSize @objc optional func insetForSection(collectionView Collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> UIEdgeInsets @objc optional func lineSpacing(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGFloat /// The spacing between the left and right of each section item (default: 0) @objc optional func interitemSpacing(collectionView Collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGFloat /// Space between section header and last section footer (default: 0) @objc optional func spacingWithLastSection(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGFloatCopy the code

Finally, a link to the demo is attached: github.com/RoganZheng/… Hit star if it helps you.