Ios-uicollectionviewlayout Method Introduction

Source: Internet
Author: User

Note: The custom function of Uicollectionview is to implement the subclass of Uicollectionviewlayout, and then rewrite the corresponding method to implement the cell layout.

1. The Preparelayout function is called when the layout is first loaded

-(void) preparelayout;

2. Custom Contentsize This method returns the size of the CollectionView, which is also a method that must be implemented in a custom layout

3. The method returns an array that holds the Uicollectionviewlayoutattributes property that is bound for each cell

-(Nsarray *) Layoutattributesforelementsinrect: (cgrect) rect;

4. To customize the properties of each cell in this method

-(Uicollectionviewlayoutattributes *) Layoutattributesforitematindexpath: (Nsindexpath *) IndexPath;

5. The method is to obtain the layoutatrributes that the cell binds to by Indexpath, and then to change some properties of the Uicollectionviewlayoutattributes object and return

-(Uicollectionviewlayoutattributes *) Layoutattributesforsupplementaryviewofkind: (NSString *) elementKind Atindexpath: (Nsindexpath *) Indexpath;

6. This method is for header view or Footerview to customize its corresponding uicollectionviewlayoutattributes

-(Uicollectionviewlayoutattributes *) Layoutattributesfordecorationviewofkind: (nsstring*) ElementKind AtIndexPath :(Nsindexpath *) Indexpath;

Uicollectionviewlayoutattributes commonly used properties:

// default is 0 // as an optimization, Uicollectionview might don't create a view for items whose hidden attribute are YES

Ios-uicollectionviewlayout Method Introduction

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.