测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年1月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✗ |
由Jeremy Groh维护。
它是UICollectionViewLayout的子类,用作UICollectionView的布局对象。QuiltView可用于iOS和tvOS,用Swift编写,基于Objective-C的RFQuiltLayout库。
QuiltView是RFQuiltLayout的Swift版本,但并非所有功能都一定移植了,且增加了一些额外的功能。
pod QuiltView
pod install
安装pod将布局作为您的UICollectionView的子类添加。为此,您设置Layout值为Custom,然后选择QuiltView
作为Class
和Module
将QuiltView导入到控制器中:import QuiltView
在托管UICollectionView的控制器上设置QuiltViewDelegate
。接下来,根据您想要单元格如何显示,您可以设置它们的宽度和高度。您可以将宽度和高度设置为不同的值以创建矩形形状,或者将宽度和高度设置为相同的值以创建正方形。
extension ViewController : QuiltViewDelegate {
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, blockSizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
// get random width and height values for the cells
let width = self.numberWidths[indexPath.row]
let height = self.numberHeights[indexPath.row]
return CGSize(width: width, height: height)
}
// Set the spacing between the cells
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetsForItemAtIndexPath indexPath: IndexPath) -> UIEdgeInsets {
return UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
}
}
以下代码显示了如何重写QuiltView的默认设置
let layout = self.collectionView?.collectionViewLayout as! QuiltView
// Set the layout to .horizontal if you want to scroll horizontally.
// This setting is optional as the default is Vertical
layout.scrollDirection = UICollectionViewScrollDirection.vertical
// This sets the block or cell size. When the sizes are equal squares will be created.
// When the sizes are different, rectangular cells will be created. The default size
// set by the library is 314 x 314.
layout.itemBlockSize = CGSize(
width: 75,
height: 75
)
注意: 所有的代理方法和属性都是可选的
QuiltView受MIT许可证的约束。有关更多信息,请参阅LICENSE文件。
请参阅发布页面。