开发者社区 问答 正文

关于IOS中uicollectionview有没有headerview 的问题

tableview有tableheaderview,uicollectionview有没有与之相似的"cllection headerview"?我知道uicollectionview可以设置每个分组的页眉页脚,但没找到整个uicollectionview上面的headerView,上面要加个轮播图。

展开
收起
爵霸 2016-03-13 10:46:42 4780 分享 版权
1 条回答
写回答
取消 提交回答
  • UICollectionView作为比UITableView更强大的封装,自然是有headerfooter的。
    UICollectionView有一个delegate,
    (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

    这个方法中可以生成一个UICollectionReusableView,顾名思义是一个可重用的view,与UITableView中重用cell的意思一样。
    这个UICollectionReusableView有两种不同类型,分别是UICollectionElementKindSectionHeaderUICollectionElementKindSectionFooter,这就是你要找的header和footer了。

    一个UICollectionReusableView的生成例子如下

    UICollectionReusableView *view = [_collectionView
     dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
     withReuseIdentifier:TheReuseID
     forIndexPath:indexPath];
    2019-07-17 19:02:05
    赞同 展开评论
问答分类:
问答标签:
问答地址: