测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2014年12月 |
由 YU JOHNNY ZHOU 维护。
YJZAlbumCollectionViewLayout 是 UICollectionViewLayout 的子类,用作 UICollectionView 的布局对象。
YJZAlbumCollectionViewLayout 的理念受 RFQuiltLayout 的启发。它的目的是允许用户简单地创建他们想要的各种收藏布局。
默认 | 自定义 |
---|---|
将布局作为您的 UICollectionViewLayout 的子类添加。
以下代码用于创建上述自定义集合布局
- (void) viewDidLoad {
// ...
YJZAlbumCollectionViewLayout* layout = (id)[self.collectionView collectionViewLayout];
[layout clearLayout];
[layout addLayoutWithRowWidth:320.f rowHeight:100.f layouts:@[[NSValue valueWithCGRect:CGRectMake(0.f, 0.f, 80.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(80.f, 0.f, 80.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(160.f, 0.f, 80.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(240.f, 0.f, 80.f, 100.f)]]];
[layout addLayoutWithRowWidth:320.f rowHeight:100.f layouts:@[[NSValue valueWithCGRect:CGRectMake(0.f, 0.f, 160.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(160.f, 0.f, 80.f, 50.f)],[NSValue valueWithCGRect:CGRectMake(240.f, 0.f, 80.f, 50.f)],[NSValue valueWithCGRect:CGRectMake(160.f, 50.f, 80.f, 50.f)],[NSValue valueWithCGRect:CGRectMake(240.f, 50.f, 80.f, 50.f)]]];
layout.delegate = self;
// ...
}
- (UIEdgeInsets) insetsForItemAtIndexPath:(NSIndexPath *)indexPath {
return UIEdgeInsetsMake(2.f, 2.f, 2.f, 2.f);
}
(注意:所有代理方法都是可选的)
必须在调用 prepareLayout 之前调用所有 api 方法。
// add a custom row layout
- (void) addLayoutWithRowWidth:(CGFloat) rowWidth rowHeight:(CGFloat) rowHeight layouts:(NSArray*) layouts;
//clear all current layouts
- (void) clearLayout;