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