collection官网 如何纯代码给UICollectionView添加HeaderView?

如何纯代码给UICollectionView添加HeaderView?从uicollectionreusableview继承。例如,@interface headercrview:uicollecti

如何纯代码给UICollectionView添加HeaderView?

从uicollectionreusableview继承。

例如,@interface headercrview:uicollectionreusableview

然后通过registerclass在VC中注册该类

[自收集视图registerClass:[HeaderCRView类]

对于SupplementaryViewOfKind:UICollectionElementKindSectionHeader

使用识别器:kheaderIdentifier

]当然,此设置应该别忘了

-(cgsize)collectionview:(uicollectionview

*)collectionview layout:(uicollectionviewlayout*)collectionviewlayout

引用headerinsect的大小:(nsinteger)section{

cgsize={320,45}

返回大小

uicollectionviewlayout通常是一个抽象类,抽象类只定义子类的一些公共属性和行为,不能直接使用。Uicollectionviewflowlayout是流水线布局,这意味着UI控件将像流水线一样,一行将满,下一行将自动排列。当然,布局方法都是由apple编写的,因此如果使用抽象类,则需要编写自己的布局