Collection View Custom Layouts
Implementing the Layout Functions
As well as the custom functions needed to calculate the placement of the numerals and hands, there are a number of UICollectionViewLayout functions that you will need to implement.
Let’s start the process of building the custom layout by implementing the following:
prepareLayout
collectionViewContentSize
layoutAttributesForElementsInRect: layoutAttributesForItemAtIndexPath:
Let’s break these calculations down into four stages:
A “master” function called calculateAllAttributes that iterates across the entire data model and calls the appropriate function to calculate the attributes for each date item in turn.
A function called calculateAttributesForItemAtIndexPath that takes the indexPath for a data item, and calls the appropriate calculation function depending on the type of item (hour, minute, or second hand) or hour label.
A function to calculate the position of the three hand cells:calculate AttributesForHandCellAtIndexPath:
A function to calculate the position of the hour labels: calculateAttributesForHourLabelWithIndexPath: