CollectionView of iOS development to design header and footer tutorials in storyboard

Source: Internet
Author: User

Header and footer are additions to the layout of the view flow. By default, these views are disabled in the flow layout. However, there are several things you can do to configure header and footer views:

First, drag CollectionView, and related settings

In storyboard, select Collection View in the Collection view controller. In Attributes Inspector, select section Header and section Footer, and once selected you will see collection Showing his header and his footer.b7a4a035-9845-47e3-b2ef-0e392e884841.


The default is null between header and footer, and we use storyboard to design the view. The head is specifically used to display a section of the caption, while the bottom view displays only static banner pictures.

Ii. implementation of Viewforsupplementaryelementofkind method

If you try to run the application, you may not see headers and footer, because we haven't implemented the "Viewforsupplementaryelementofkind:" method.

The code is as follows:


-(Uicollectionreusableview *) CollectionView: (Uicollectionview *) CollectionView Viewforsupplementaryelementofkind :(NSString *) kind Atindexpath: (Nsindexpath *) Indexpath
{
Uicollectionreusableview *reusableview = nil;

if (kind = = Uicollectionelementkindsectionheader) {

Uicollectionreusableview *headerview = [CollectionView dequeuereusablesupplementaryviewofkind: Uicollectionelementkindsectionheader withreuseidentifier:@" headerview" Forindexpath:indexpath];
Reusableview = Headerview;

}

if (kind = = Uicollectionelementkindsectionfooter) {

Uicollectionreusableview *footerview = [CollectionView dequeueresuablesupplementaryviewofkind: Uicollectionelementkindsectionfooter withreuseidentifier:@" footerview" Forindexpath:indexpath];

Reusableview = Footerview;

}

return reusableview;

}
The above code tells it that the header/footer view should use Collect view in each section. We first determine that the collection view requires header or footer view. This can be done by using a variable. For the head, we column header view (using the Dequeuereusablesupplementaryviewofkind: method) and set the appropriate title and image. As you can from the two if code between, we use our previous assignment to get the Header/footer view identifier.

Related Article

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.