Uicollection similar to TableView title

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.