- 设计优雅,使用方便
- 可适用于各种各样的流式布局
- 纯Swift项目
- iOS 8.0+
- Xcode 8.3+
- Swift 3.1+
Podfile配置如下:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'ZJFlexibleLayout'
endCartfile配置如下:
github "zzjzz9266a/ZJFlexibleLayout"
运行 carthage update 之后把生成的ZJFlexibleLayout.framework 拖进项目。
1、创建一个 ZJFlexibleLayout并添加代理,在创建UICollectionView的时候把layout传进去:
let layout = ZJFlexibleLayout(delegate: self)
layout.collectionHeaderView = headerView //could be nil
collectionView = UICollectionView(frame: kScreenBounds, collectionViewLayout: layout)2、实现协议ZJFlexibleDataSource,只需要实现前两个方法即可:
protocol ZJFlexibleLayoutDataSource: class{
//控制对应section的瀑布流列数
func numberOfCols(at section: Int) -> Int
//控制每个cell的尺寸,实质上就是获取宽高比
func sizeOfItemAtIndexPath(at indexPath : IndexPath) -> CGSize
//控制瀑布流cell的间距
func spaceOfCells(at section: Int) -> CGFloat
//section 内边距
func sectionInsets(at section: Int) -> UIEdgeInsets
//每个section的header尺寸
func sizeOfHeader(at section: Int) -> CGSize
//每个cell的额外高度
func heightOfAdditionalContent(at indexPath : IndexPath) -> CGFloat
}ZJFlexibleDataLayout 遵循 MIT 开源协议,具体查看LICENSE.
