Remember the first time to write CollectionView title, check a lot of data results found are not very complete, after efforts or do come out now share with you, let the small partners in the pit quickly out of the pit nonsense less say straight start
In the case of creating a good collection, we start the first step.
First, create a class that inherits from the Uicollectionreusableview
Then register head view in CollectionView
Static @" Headeridentifier " class] Forsupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier: Kheaderidentifier];
Yyclassreusable is a class that inherits from the Uicollectionreusableview----continue to define the size of the header head next
-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (Uicollectionviewlayout *) Collectionviewlayout referencesizeforheaderinsection: (nsinteger) section{ ); return size;}
The last step in the Uicollectionviewdatasource agent has a method
#pragmaMark--Set head end Content-(Uicollectionreusableview *) CollectionView: (Uicollectionview *) CollectionView Viewforsupplementaryelementofkind: (NSString *) kind Atindexpath: (Nsindexpath *) indexpath{Uicollectionreusableview*reusableview =Nil;#pragmaMark-Customizing the contents of the head viewif(Kind = =Uicollectionelementkindsectionheader) {yyclassreusable*headerv = (Yyclassreusable *) [CollectionView Dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader Withreuseidentifier:kheaderidentifier Forindexpath:indexpath]; if(Indexpath.section = =0) {[Headerv settitle:@"I'm Heading 1 ."]; }Else{[Headerv settitle:@"I'm Heading 2 ."]; } Reusableview=Headerv; } returnReusableview;}
The basic is the above three steps, you can complete, if there is anything you need to add, I will discuss each other
The final ritual is attached to the demo----Http://pan.baidu.com/s/1eRmQamI
Uicollection similar to TableView title