Custom UICollectionViewlayout

Disclaimer: This article is a blogger original article, reproduced, please indicate the source of the article. https://blog.csdn.net/SunFlowerInRain/article/details/77164782

Write pictures described here

In iOS development, UICollectionView major role role is used to display the data grid pattern, compared to TableView, collectionView layout more flexible, it can be customized UICollectionViewLayout, to achieve the effect of UI we need.

The main role of UICollectionView is used to display the data grid pattern, compared to TableView, collectionView more flexible and can be customized UICollectionViewLayout, to control the layout CollectionView object to the UI effect we need.

UICollectionViewLayout Description:

UICollectionViewLayout itself does not draw UI, collectionView the UI drawing is done by the agent data source.

UICollectionViewLayout primarily responsible for controlling the position and size of each object needs layout. Object control comprises Cells, Supplementary views (header, footer), Decoration views (decorative background). Implement custom layout needs to be rewritten a series of parent class UICollectionViewlayout.

The method needs to be rewritten:

collectionViewContentSize : Setting the width and height to set collectionview of contentsize;

layoutAttributesForElementsInRect : to rect layout attribute set where each cell

layoutAttributesForItemAtIndexPath : Set layout attribute for each cell itself.

layoutAttributesForSupplementaryViewOfKind: atIndexPath: (If you need to load the Supplementary views) layout attribute is set for the supplementary views.

layoutAttributesForDecorationViewOfKind: atIndexPath: (If you need to load DecorationView) layout attribute set to DecorationView

shouldInvalidateLayoutForBoundsChange: When the bounds object layout change is the emergence of whether or not to re-layout layout.

Project Address: https://github.com/LINDreaming/DailyTools

Guess you like

Origin blog.csdn.net/SunFlowerInRain/article/details/77164782