UICollectionView 设置headView

从 UICollectionReusableView 继承。

@interface HeaderCRView : UICollectionReusableView

然后在Vc里面通过registerClass把该类注册进去

 [self.collectionView registerClass:[HeaderCRView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kheaderIdentifier];

当然这个设置不能忘记

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    CGSize size={320,45};
    return size;
}

你可能感兴趣的:(UICollectionView 设置headView)