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.

  1. aspectRatioForItemAtIndexPath (delegate)
  2. heightForItemAtIndexPath (delegate)
  3. 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 }