关于UICollectionView Section头尾视图

用 xib 生成 UICollectionViewSection 头尾视图


首先注册一个 UICollectionReusableView 类 ps:不注册会crash

[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];

记住在XIB中 设置高度  以及开启头尾视图设置


头尾视图
宽高 宽度不设置默认于视图一样


再这个方法里生成头视图

- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

{

UICollectionReusableView *reusableview = nil;

判断为头视图 或 尾视图 

UICollectionElementKindSectionFooter 

UICollectionElementKindSectionHeader

if (kind == UICollectionElementKindSectionHeader)

从队列取头视图

UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

reusableview = headerView;

}

reusable view 其实就是一个view 

reusableview.backgroundColor = [UIColor redColor];

return reusableview;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容