tableview有tableheaderview,uicollectionview有没有与之相似的"cllection headerview"?我知道uicollectionview可以设置每个分组的页眉页脚,但没找到整个uicollectionview上面的headerView,上面要加个轮播图。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
UICollectionView
作为比UITableView
更强大的封装,自然是有header
和footer
的。
UICollectionView
有一个delegate,(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
这个方法中可以生成一个UICollectionReusableView
,顾名思义是一个可重用的view,与UITableView
中重用cell的意思一样。
这个UICollectionReusableView
有两种不同类型,分别是UICollectionElementKindSectionHeader
和UICollectionElementKindSectionFooter
,这就是你要找的header和footer了。
一个UICollectionReusableView的生成例子如下
UICollectionReusableView *view = [_collectionView
dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:TheReuseID
forIndexPath:indexPath];