UICollectionViewFlowLayout Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 6.0 and later. |
| Declared in | UICollectionViewFlowLayout.h |
Overview
The UICollectionViewFlowLayout class is a concrete layout object that organizes items into a grid with optional header and footer views for each section. The items in the collection view flow from one row or column (depending on the scrolling direction) to the next, with each row comprising as many cells as will fit. Cells can be the same sizes or different sizes.
A flow layout works with the collection view’s delegate object to determine the size of items, headers, and footers in each section and grid. That delegate object must conform to the UICollectionViewDelegateFlowLayout protocol. Use of the delegate allows you to adjust layout information dynamically. For example, you would need to use a delegate object to specify different sizes for items in the grid. If you do not provide a delegate, the flow layout uses the default values you set using the properties of this class.
Flow layouts lay out their content using a fixed distance in one direction and a scrollable distance in the other. For example, in a vertically scrolling grid, the width of the grid content is constrained to the width of the corresponding collection view while the height of the content adjusts dynamically to match the number of sections and items in the grid. The layout is configured to scroll vertically by default but you can configure the scrolling direction using the scrollDirection property.
Each section in a flow layout can have its own custom header and footer. To configure the header or footer for a view, you must configure the size of the header or footer to be non zero. You can do this by implementing the appropriate delegate methods or by assigning appropriate values to the headerReferenceSize and footerReferenceSize properties. If the header or footer size is 0, the corresponding view is not added to the collection view.
Tasks
Configuring the Scroll Direction
-
scrollDirectionproperty
Configuring the Item Spacing
-
minimumLineSpacingproperty -
minimumInteritemSpacingproperty -
itemSizeproperty -
sectionInsetproperty
Configuring the Supplementary Views
-
headerReferenceSizeproperty -
footerReferenceSizeproperty
Properties
footerReferenceSize
The default sizes to use for section footers.
Discussion
If the delegate does not implement the collectionView:layout:referenceSizeForFooterInSection: method, the flow layout object uses the default footer sizes set for this property.
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.
The default size values are (0, 0).
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
UICollectionViewFlowLayout.hheaderReferenceSize
The default sizes to use for section headers.
Discussion
If the delegate does not implement the collectionView:layout:referenceSizeForHeaderInSection: method, the flow layout object uses the default header sizes set in this property.
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.
The default size values are (0, 0).
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewFlowLayout.hitemSize
The default size to use for cells.
Discussion
If the delegate does not implement the collectionView:layout:sizeForItemAtIndexPath: method, the flow layout uses the value in this property to set the size of each cell. This results in cells that all have the same size.
The default size value is (50.0, 50.0).
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewFlowLayout.hminimumInteritemSpacing
The minimum spacing to use between items in the same row.
Discussion
If the delegate object does not implement the collectionView:layout:minimumInteritemSpacingForSectionAtIndex: method, the flow layout uses the value in this property to set the spacing between items in the same line.
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.
The default value of this property is 10.0.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewFlowLayout.hminimumLineSpacing
The minimum spacing to use between lines of items in the grid.
Discussion
If the delegate object does not implement the collectionView:layout:minimumLineSpacingForSectionAtIndex: method, the flow layout uses the value in this property to set the spacing between lines in a 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.
The default value of this property is 10.0.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewFlowLayout.hscrollDirection
The scroll direction of the grid.
Discussion
The grid layout scrolls along one axis only, either horizontally or vertically. For the non scrolling axis, the width of the collection view in that dimension serves as starting width of the content.
The default value of this property is UICollectionViewScrollDirectionVertical.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewFlowLayout.hsectionInset
The margins used to lay out content in a section
Discussion
If the delegate object does not implement the collectionView:layout:insetForSectionAtIndex: method, the flow layout uses the value in this property to set the margins for each section.
Section insets reflect the spacing at the outer edges of the section. The margins affect the initial position of the header view, the minimum space on either side of each line of items, and the distance from the last line to the footer view. The margin insets do not affect the size of the header and footer views in the non scrolling direction.
The default edge insets are all set to 0.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewFlowLayout.hConstants
UICollectionViewScrollDirection
Constants indicating the direction of scrolling for the layout.
enum {
UICollectionViewScrollDirectionVertical,
UICollectionViewScrollDirectionHorizontal
};
typedef NSUInteger UICollectionViewScrollDirection;
Constants
UICollectionViewScrollDirectionVerticalThe layout scrolls content vertically.
Available in iOS 6.0 and later.
Declared in
UICollectionViewFlowLayout.h.UICollectionViewScrollDirectionHorizontalThe layout scrolls content horizontally.
Available in iOS 6.0 and later.
Declared in
UICollectionViewFlowLayout.h.
Flow Layout Supplementary Views
Constants that specify the types of supplementary views that can be presented using a flow layout.
NSString *const UICollectionElementKindSectionHeader; NSString *const UICollectionElementKindSectionFooter;
Constants
UICollectionElementKindSectionHeaderA supplementary view that identifies the header for a given section.
Available in iOS 6.0 and later.
Declared in
UICollectionViewFlowLayout.h.UICollectionElementKindSectionFooterA supplementary view that identifies the footer for a given section.
Available in iOS 6.0 and later.
Declared in
UICollectionViewFlowLayout.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)