Custom UICollectionView Layout-entry, uicollectionview Layout

Source: Internet
Author: User

Custom UICollectionView Layout-entry, uicollectionview Layout
Custom UICollectionView Layout-entry 0. application scenarios:

Various cells are often used in projects. Sometimes custom cells cannot meet product requirements. We can choose a complicated and difficult development method to solve the problem, of course, you can also choose a simple but skillful solution. The custom UICollectionView layout is a good way. This section describes how to use the custom UICollectionView layout to create a beautiful interface.

1. Inheritance plan
  • 1> inherit from UICollectionViewLayout
  • 2> inherit from UICollectionViewFlowLayout
2. methods that may need to be rewritten
  • 1> prepareLayout

    • Set some initialization parameters here to perform initialization.
    • You must call [super prepareLayout];
  • 2> layoutAttributesForElementsInRect:

    • The returned array contains the UICollectionViewLayoutAttributes object.
    • Return the layout attribute of all elements (such as cell) in collectionView: This method determines how the cell is arranged.
    • Each cell has its own layout attribute: UICollectionViewLayoutAttributes
  • 3> shouldInvalidateLayoutForBoundsChange:

    • Whether to refresh the layout when the bounds of the uicollectionView changes
    • Once you refresh the layout, the methods 1> and 2> are called in sequence.
  • 4> targetContentOffsetForProposedContentOffset: withScrollingVelocity:

    • The returned value of this method determines the final offset of collectionView (the final position)
    • ProposedContentOffset parameter: the offset of collectionView.
    • Velocity parameter: Rolling rate of collectionView
  • 5> layoutAttributesForItemAtIndexPath:

    • If you inherit UICollectionViewLayout, you 'd better implement this method.
    • Purpose: return the layout attribute of the cell in the indexPath position.

PS: code will be uploaded later.

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.