CZCustomLayout
CZCustomLayout 是 UICollectionViewFlowLayout 的子类。
这个布局受 Pinterest 的启发,使用 CHTCollectionViewWaterfallLayout,它允许您使用自动尺寸
功能
- 易于使用。
- 可定制。
- 支持头部和尾部视图。
- 每个部分自定义列数。
先决条件
- ARC
- Xcode 7.1+.
- iOS 9+
如何安装
-
- 在 Podfile 中添加
pod 'CZCustomLayout'
- 在 Podfile 中添加
-
手动
- 将
BaseCollectionViewLayout.swift
拷贝到您的项目中。
- 将
如何使用
步骤 1
import CZCustomLayout
为了遵循 BaseCollectionViewLayoutProtocol 协议,您必须在您的 UIViewController 中实现该协议。
步骤 2
为了遵循 CZeyboardObserverDelegate,您需要实现以下函数
func collectionView (_ collectionView: UICollectionView, availableWidth: CGFloat, heightForItemAtIndexPath indexPath: IndexPath) -> CGFloat
--option--
func collectionView (_ collectionView: UICollectionView, availableWidth: CGFloat, heightForHeaderInSection section: Int) -> CGFloat
func collectionView (_ collectionView: UICollectionView, availableWidth: CGFloat, heightForFooterInSection section: Int) -> CGFloat
func collectionView (_ collectionView: UICollectionView, columnCountForSection section: Int) -> Int
func collectionViewBiggerCell(_ indexPath: IndexPath) -> Bool
步骤 3
在 viewcontroller 中配置布局
//create the Layout
let layout = BaseCollectionViewLayout()
//config margin
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10)
// The minimum spacing to use between rows.
layout.minimumInteritemSpacing = 10
// The minimum spacing to use between columns
layout.minimumLineSpacing = 10
// number of columns or implement collectionView (_ collectionView: UICollectionView, columnCountForSection section: Int)
layout.numberOfColumns = 2
// Add the layout to your collection view
self.collectionView.collectionViewLayout = layout
//add delegate
layout.delegate = self
限制
- 仅支持垂直滚动。
- 无装饰视图。
许可协议
CZCustomLayout 是在 MIT 许可下授权的。有关更多详细信息,请参阅 LICENSE。