WaterfallLayout
iOS 中的瀑布流布局
功能
- 可以选择每个区域的流动/瀑布布局。
- 可用的自定义大小传入项。
如何使用
class ViewController: UIViewController {
@IBOutlet private weak var collectionView: UICollectionView! {
didSet {
let layout = WaterfallLayout()
layout.delegate = self
layout.sectionInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
layout.minimumLineSpacing = 8.0
layout.minimumInteritemSpacing = 8.0
layout.headerHeight = 50.0
collectionView.collectionViewLayout = layout
collectionView.register(...)
collectionView.dataSource = self
collectionView.delegate = self
}
}
}
extension ViewController: UICollectionDataSource {
...
}
extension ViewController: WaterfallLayoutDelegate {
func collectionViewLayout(for section: Int) -> WaterfallLayout.Layout {
switch section {
case 0: return .flow(column: 1) // single column flow layout
case 1: return .waterfall(column: 3) // three waterfall layout
default: return .flow(column: 2)
}
}
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(...)
}
}
属性
public var minimumLineSpacing: CGFloat { get set }
public var minimumInteritemSpacing: CGFloat { get set }
public var sectionInset: UIEdgeInsets { get set }
public var headerHeight: CGFloat { get set }
public var headerInset: UIEdgeInsets { get set }
public var footerHeight: CGFloat { get set }
public var footerInset: UIEdgeInsets { get set }
public var estimatedItemSize: CGSize { get set }
布局代理
public protocol WaterfallLayoutDelegate: class {
// MARK: - Required
func collectionViewLayout(for section: Int) -> WaterfallLayout.Layout
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
// MARK: - Optional
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, minimumInteritemSpacingFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, minimumLineSpacingFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sectionInsetFor section: Int) -> UIEdgeInsets?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, headerHeightFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, headerInsetFor section: Int) -> UIEdgeInsets?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, footerHeightFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, footerInsetFor section: Int) -> UIEdgeInsets?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, estimatedSizeForItemAt indexPath: IndexPath) -> CGSize?
}
需求
- iOS 9.0+
- Xcode 9+
- Swift 4+
安装
Carthage
- 请在您的 Cartfile 中添加以下内容
github "sgr-ksmt/WaterfallLayout" ~> 0.1
- 运行
carthage update
- 按描述添加框架。
详细信息: Carthage 读取文档
CocoaPods
WaterfallLayout 通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行
pod 'WaterfallLayout', '~> 0.1'
然后运行 pod install
手动安装
下载所有 *.swift
文件并将其放入您的项目中。
变更日志
变更日志在这里:变更日志。
交流
- 如果您发现了错误,请打开一个问题。
- 如果您有功能请求,请打开一个问题。
- 如果您想投稿,请提交一个pull请求。
💪
许可证
WaterfallLayout遵循MIT许可证。更多信息请参阅LICENSE文件。