iOS:YHWaterFallLayout 瀑布流简易使用

560 阅读1分钟

YHWaterFallLayout

瀑布流简易使用

示例

example.gif

安装

CocoaPods (推荐)

  1. 编辑你的Podfile.
pod 'YHWaterFallLayout', :git => 'https://github.com/yelinux/YHWaterFallLayout.git'
  1. 执行 pod installpod update.

手动集成

  1. 拖动文件夹 YHWaterFallLayout 到你的项目.

Usage

  1. 引用头文件:
#import "YHWaterFallLayout.h"
  1. 创建collectionViewLayout实例:YHWaterFallLayout
YHWaterFallLayout *layout = [[YHWaterFallLayout alloc] init];
layout.minimumLineSpacing = 5;
layout.minimumInteritemSpacing = 5;
layout.sectionInset = UIEdgeInsetsMake(8, 8, 8, 8);
layout.delegate = self;
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
  1. 配置delegate: YHWaterFallLayoutDelegate
//@optional
-(CGSize)yHWaterFallLayout:(YHWaterFallLayout *)layout sizeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
    } else {
    }
}
//@required
-(CGSize)yHWaterFallLayout:(YHWaterFallLayout *)layout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
}
  1. 配置 UICollectionView's delegate 和 datasource: UICollectionViewDelegate, UICollectionViewDataSource
//@optional
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
}
//@optional
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
}
//@required
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
}
//@required
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
}

源码

Github地址