首先你需要自定义这几个类
自定义flowLayout
重写几个方法:
- (instancetype)init
- (void)prepareLayout
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
在我们自定义的flowlayout里需要自定义一个协议这样外部就能穿入一些东西来帮助我们设置组的背景view各种属性
@protocol JHCollectionViewDelegateFlowLayout
- (UIColor *)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout backgroundColorForSection:(NSInteger)section;
@end
在prepare方法里可以看到调用这个方法。
init
初始化一些属性,或者注册我们要设置的组背景。
NSString *const JHCollectionViewSectionBackground = @"JHCollectionViewSectionBackground";
@implementation JHCollectionViewFlowLayout
- (instancetype)init
{
self = [super init];
if (self) {