CollectionViewColumnLayout
open class CollectionViewColumnLayout : CollectionViewLayout
This layout is column based which means you provide the number of columns and cells are placed in the appropriate one. It can be display items all the same size or as a Pinterest
style layout.
The number of columns can be set dynamically by the delegate or you can provide a default value using layout.columnCount
.
You can also set the sectionInsets
and minimumColumnSpacing
which will affect the width of each column.
With the itemWidth set by the column, you have 3 options to set the height of each item. They are used in the order here. So if aspectRatioForItemAtIndexPath is implemented it is used, otherwise, it checks the next one.
- aspectRatioForItemAtIndexPath (delegate)
- heightForItemAtIndexPath (delegate)
- layout.defaultItemHeight
The delegate method aspectRatioForItemAtIndexPath scales the size of the cell to maintain that ratio while fitting within the caclulated column width.
Mixed use of ratios and heights is also supported. Returning CGSize.zero for a ratio will fall back to the hight. If a valid ratio and height are provided, the height will be appended to the height to respect the ratio. For example, if the column width comes out to 100, a ratio of 2 will determine a height of 200. If a height is also provided by the delegate for the same item, say 20 it will be added, totalling 220.
-
The method to use when directing items into columns
- shortestFirst: Use the current column
- leftToRight: Always insert left to right
- rightToLeft: Always insert right to left
Declaration
Swift
public enum LayoutStrategy
-
The default column count
Declaration
Swift
open var columnCount: NSInteger { get set }
-
The spacing between each column
Declaration
Swift
open var columnSpacing: CGFloat { get set }
-
The vertical spacing between items in the same column
Declaration
Swift
open var interitemSpacing: CGFloat { get set }
-
The height of section header views
Declaration
Swift
open var headerHeight: CGFloat { get set }
-
The height of section footer views
Declaration
Swift
open var footerHeight: CGFloat { get set }
-
The default height to apply to all items
Declaration
Swift
open var itemHeight: CGFloat { get set }
-
If supplementary views should respect section insets or fill the CollectionView width
Declaration
Swift
open var insetSupplementaryViews: Bool { get set }
-
If set to true, the layout will invalidate on all bounds changes, if false only on width changes
Declaration
Swift
open var invalidateOnBoundsChange: Bool { get set }
-
Default insets for all sections
Declaration
Swift
open var sectionInset: NSEdgeInsets { get set }
-
A hint as to how to render items when deciding which column to place them in
Declaration
Swift
open var layoutStrategy: CollectionViewColumnLayout.LayoutStrategy { get set }
-
Declaration
Swift
override open func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool
-
Declaration
Swift
override open func prepare()
-
Declaration
Swift
override open var collectionViewContentSize: CGSize { get }
-
Declaration
Swift
open override func rectForSection(_ section: Int) -> CGRect
-
Declaration
Swift
open override func contentRectForSection(_ section: Int) -> CGRect
-
Declaration
Swift
open override func layoutAttributesForItems(in rect: CGRect) -> [CollectionViewLayoutAttributes]
-
Declaration
Swift
open override func layoutAttributesForItem(at indexPath: IndexPath) -> CollectionViewLayoutAttributes?
-
Declaration
Swift
open override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> CollectionViewLayoutAttributes?
-
Declaration
Swift
open override func scrollRectForItem(at indexPath: IndexPath, atPosition: CollectionViewScrollPosition) -> CGRect?
-
Declaration
Swift
open override func indexPathForNextItem(moving direction: CollectionViewDirection, from currentIndexPath: IndexPath) -> IndexPath?