中文简介
ZJFlexibleLayout 是 iOS 平台上简单且灵活的水点多列布局 UI 组件。
特性
- 易于使用
- 灵活布局,包括瀑布流布局
- 完全使用 Swift 编写
要求
- iOS 8.0+
- Xcode 8.3+
- Swift 3.1+
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:
$ gem install cocoapods
构建
ZJFlexibleLayout
需要 CocoaPods 1.1+。
要使用 CocoaPods 将 ZJFlexibleLayout 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'ZJFlexibleLayout'
end
Carthage
Carthage 是一个去中心化的依赖项管理器,它可以构建您的依赖项并提供二进制框架。
您可以使用以下命令使用 Homebrew 安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 ZJFlexibleLayout 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "zzjzz9266a/ZJFlexibleLayout"
运行 carthage update
构建框架,并将构建的 ZJFlexibleLayout.framework
拖动到您的 Xcode 项目中。
使用说明
1、创建一个新的 ZJFlexibleLayout
并设置代理,将此 layout
设置为 UICollectionView
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。