项目介绍:
CHTCollectionViewWaterfallLayout是UICollectionViewLayout的子类,试图将UICollectionViewFlowLayout所有使用方法模拟了出来。
Features 功能
- 使用简单,完全模拟UICollectionViewFlowLayout‘s的使用方法。
- 拥有高度自定义功能。
- 性能出众,10000+的items对他来说都毫无压力
- 支持header and footer views.
- 不同的列可以用不同的sections
Prerequisite 环境需求
- ARC
- Xcode 4.4+, which supports literals syntax.
- iOS 6+, or
- iOS 4.x/5.x, with PSTCollectionView.
使用方法如下
Step 1
Below lists the properties for you to customize the layout. Although they have default values, I strongly recommend you to set up at least the columnCount property to suit your needs. The itemRenderDirection property is an enum which decides the order in which your items will be rendered in subsequent rows. For eg. Left-Right | Right-Left | Shortest column filling up first.
[Objective-C] 查看源文件 复制代码
@property (nonatomic, assign) NSInteger columnCount; @property (nonatomic, assign) CGFloat minimumColumnSpacing; @property (nonatomic, assign) CGFloat minimumInteritemSpacing; @property (nonatomic, assign) CGFloat headerHeight; @property (nonatomic, assign) CGFloat footerHeight; @property (nonatomic, assign) UIEdgeInsets sectionInset; @property (nonatomic, assign) ItemRenderDirection itemRenderDirection;
Step 2
Your collection view’s delegate (which often is your view controller) must conforms toCHTCollectionViewDelegateWaterfallLayout protocol and implements the required method, all you need to do is return the original size of the item:
[Objective-C] 查看源文件 复制代码
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
DEMO 直接下载 (OC 和 Swift):