如何纯代码给UICollectionView添加HeaderView

2025-05-17 17:02:37
推荐回答(1个)
回答1:

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;
}