SNCollectionViewLayout
屏幕截图
示例
要运行示例项目,请克隆仓库,然后首先从示例目录运行 pod install
使用
1- 创建实例
let snCollectionViewLayout = SNCollectionViewLayout()
snCollectionViewLayout.fixedDivisionCount = 4 // Columns for .vertical, rows for .horizontal
snCollectionViewLayout.delegate = self
myCollectionView.collectionViewLayout = snCollectionViewLayout
2- 委托
// scale for items based number of columns
func scaleForItem(inCollectionView collectionView: UICollectionView, withLayout layout: UICollectionViewLayout, atIndexPath indexPath: IndexPath) -> UInt {
if indexPath.row == 0 || indexPath.row == 3 || indexPath.row == 10 || indexPath.row == 70 {
return 2
}
return 1
}
// height for item if set fixedDimension height equal width
func itemFlexibleDimension(inCollectionView collectionView: UICollectionView, withLayout layout: UICollectionViewLayout, fixedDimension: CGFloat) -> CGFloat {
return fixedDimension
}
// header height
func headerFlexibleDimension(inCollectionView collectionView: UICollectionView, withLayout layout: UICollectionViewLayout, fixedDimension: CGFloat) -> CGFloat {
return 0
}
要求
- Swift 4.2+
- Xcode 10.0+
- iOS 11.0+
安装
SNCollectionViewLayout 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile 中
pod 'SNCollectionViewLayout'
作者
ahmedAlmasri,[email protected]
许可
SNCollectionViewLayout 在 MIT 许可证下可用。更多信息请参阅 LICENSE 文件。