XRWaterfallLayout.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // XRWaterfallLayout.h
  3. //
  4. // Created by 肖睿 on 16/3/29.
  5. // Copyright © 2016年 XR. All rights reserved.
  6. //
  7. #import <UIKit/UIKit.h>
  8. @class XRWaterfallLayout;
  9. @protocol XRWaterfallLayoutDelegate <NSObject>
  10. @required
  11. //计算item高度的代理方法,将item的高度与indexPath传递给外界
  12. - (CGFloat)waterfallLayout:(XRWaterfallLayout *)waterfallLayout itemHeightForWidth:(CGFloat)itemWidth atIndexPath:(NSIndexPath *)indexPath;
  13. @end
  14. /**
  15. *实现了瀑布流功能,但是不能添加头部和底部视图,如项目中有添加头部或底部视图的需求,请慎用!!!
  16. */
  17. @interface XRWaterfallLayout : UICollectionViewLayout
  18. #pragma mark- 属性
  19. //总共多少列,默认是2
  20. @property (nonatomic, assign) NSInteger columnCount;
  21. //列间距,默认是0
  22. @property (nonatomic, assign) NSInteger columnSpacing;
  23. //行间距,默认是0
  24. @property (nonatomic, assign) NSInteger rowSpacing;
  25. //section与collectionView的间距,默认是(0,0,0,0)
  26. @property (nonatomic, assign) UIEdgeInsets sectionInset;
  27. //同时设置列间距,行间距,sectionInset
  28. - (void)setColumnSpacing:(NSInteger)columnSpacing rowSpacing:(NSInteger)rowSepacing sectionInset:(UIEdgeInsets)sectionInset;
  29. /**
  30. 以下代理属性与block属性二选一,用来设置每一个item的高度
  31. 会将item的宽度与indexPath传递给外界
  32. 如果两个都设置,block的优先级高,即代理无效
  33. */
  34. //代理,用来计算item的高度
  35. @property (nonatomic, weak) id<XRWaterfallLayoutDelegate> delegate;
  36. //计算item高度的block,将item的高度与indexPath传递给外界
  37. @property (nonatomic, strong) CGFloat(^itemHeightBlock)(CGFloat itemHeight,NSIndexPath *indexPath);
  38. #pragma mark- 构造方法
  39. + (instancetype)waterFallLayoutWithColumnCount:(NSInteger)columnCount;
  40. - (instancetype)initWithColumnCount:(NSInteger)columnCount;
  41. @end