开发者社区 问答 正文

UICollectionView HeaderView 怎么做

如题。我希望UICollectionView中实现类似于UITableView的tableHeaderView,怎么做啊

展开
收起
a123456678 2016-07-28 14:13:37 2406 分享 版权
1 条回答
写回答
取消 提交回答
  • 在初始化时和添加cell类似
    [collectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeadID];
    再加楼上的

    • (UICollectionReusableView )collectionView:(UICollectionView )collectionView viewForSupplementaryElementOfKind:(NSString )kind atIndexPath:(NSIndexPath )indexPath
      {

    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
    HeadView * view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeadID forIndexPath:indexPath];
    return view;
    }
    return nil;
    }

    2019-07-17 20:01:23
    赞同 展开评论
问答地址: