Protocol: UICollectionViewDelegateFlowLayout
Overview
The UICollectionViewDelegateFlowLayout protocol defines methods that let you coordinate with a UICollectionViewFlowLayout object to implement a grid-based layout. The methods of this protocol define the size of items and the spacing between items in the grid.Asks the delegate for the margins to apply to content in the specified section.Asks the delegate for the spacing between successive items in the rows or columns of a section.Asks the delegate for the spacing between successive rows or columns of a section.Asks the delegate for the size of the footer view in the specified section.Asks the delegate for the size of the header view in the specified section.Asks the delegate for the size of the specified item’s cell.
Instance Method Summary (collapse)
-
- collectionView:layout:insetForSectionAtIndex:
Asks the delegate for the margins to apply to content in the specified section.
-
- collectionView:layout:minimumInteritemSpacingForSectionAtIndex:
Asks the delegate for the spacing between successive items in the rows or columns of a section.
-
- collectionView:layout:minimumLineSpacingForSectionAtIndex:
Asks the delegate for the spacing between successive rows or columns of a section.
-
- collectionView:layout:referenceSizeForFooterInSection:
Asks the delegate for the size of the footer view in the specified section.
-
- collectionView:layout:referenceSizeForHeaderInSection:
Asks the delegate for the size of the header view in the specified section.
-
- collectionView:layout:sizeForItemAtIndexPath:
Asks the delegate for the size of the specified item’s cell.
Instance Method Details
- (UIEdgeInsets) collectionView(collectionView, layout:collectionViewLayout, insetForSectionAtIndex:section)
Asks the delegate for the margins to apply to content in the specified section. If you do not implement this method, the flow layout uses the value in its sectionInset property to set the margins instead. Your implementation of this method can return a fixed set of margin sizes or return different margin sizes for each section. Section insets are margins applied only to the items in the section. They represent the distance between the header view and the first line of items and between the last line of items and the footer view. They also indicate they spacing on either side of a single line of items. They do not affect the size of the headers or footers themselves.
- (Float) collectionView(collectionView, layout:collectionViewLayout, minimumInteritemSpacingForSectionAtIndex:section)
Asks the delegate for the spacing between successive items in the rows or columns of a section. If you do not implement this method, the flow layout uses the value in its minimumInteritemSpacing property to set the space between items instead. Your implementation of this method can return a fixed value or return different spacing values for each section. For a vertically scrolling grid, this value represents the minimum spacing between items in the same row. For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column. This spacing is used to compute how many items can fit in a single line, but after the number of items is determined, the actual spacing may possibly be adjusted upward.
- (Float) collectionView(collectionView, layout:collectionViewLayout, minimumLineSpacingForSectionAtIndex:section)
Asks the delegate for the spacing between successive rows or columns of a section. If you do not implement this method, the flow layout uses the value in its minimumLineSpacing property to set the space between lines instead. Your implementation of this method can return a fixed value or return different spacing values for each section. For a vertically scrolling grid, this value represents the minimum spacing between successive rows. For a horizontally scrolling grid, this value represents the minimum spacing between successive columns. This spacing is not applied to the space between the header and the first line or between the last line and the footer.
- (CGSize) collectionView(collectionView, layout:collectionViewLayout, referenceSizeForFooterInSection:section)
Asks the delegate for the size of the footer view in the specified section. If you do not implement this method, the flow layout uses the value in its footerReferenceSize property to set the size of the footer. During layout, only the size that corresponds to the appropriate scrolling direction is used. For example, for the vertical scrolling direction, the layout object uses the height value specified by this property. (In that instance, the width of the footer would be set to the width of the collection view.) If the size in the appropriate scrolling dimension is 0, no footer is added.
- (CGSize) collectionView(collectionView, layout:collectionViewLayout, referenceSizeForHeaderInSection:section)
Asks the delegate for the size of the header view in the specified section. If you do not implement this method, the flow layout uses the value in its headerReferenceSize property to set the size of the header.During layout, only the size that corresponds to the appropriate scrolling direction is used. For example, for the vertical scrolling direction, the layout object uses the height value returned by your method. (In that instance, the width of the header would be set to the width of the collection view.) If the size in the appropriate scrolling dimension is 0, no header is added.
- (CGSize) collectionView(collectionView, layout:collectionViewLayout, sizeForItemAtIndexPath:indexPath)
Asks the delegate for the size of the specified item’s cell. If you do not implement this method, the flow layout uses the values in its itemSize property to set the size of items instead. Your implementation of this method can return a fixed set of sizes or dynamically adjust the sizes based on the cell’s content. The flow layout does not crop a cell’s bounds to make it fit into the grid. Therefore, the values you return must allow for the item to be displayed fully in the collection view. For example, in a vertically scrolling grid, the width of a single item must not exceed the width of the collection view view (minus any section insets) itself. However, in the scrolling direction, items can be larger than the collection view because the remaining content can always be scrolled into view.