Class

NSCollectionLayoutBoundarySupplementaryItem

An object used to add headers or footers to a collection view.

Declaration

class NSCollectionLayoutBoundarySupplementaryItem : NSCollectionLayoutSupplementaryItem

Overview

A boundary supplementary item is a specialized type of supplementary item (NSCollectionLayoutSupplementaryItem). You use boundary supplementary items to add headers or footers to a section of a collection view or the entire collection view.

Each type of supplementary item must have a unique element kind. Consider tracking these strings together in a way that makes it straightforward to identify each element.

struct ElementKind {
    static let badge = "badge-element-kind"
    static let background = "background-element-kind"
    static let sectionHeader = "section-header-element-kind"
    static let sectionFooter = "section-footer-element-kind"
    static let layoutHeader = "layout-header-element-kind"
    static let layoutFooter = "layout-footer-element-kind"
}

Add boundary supplementary items to a section by setting that section's boundarySupplementaryItems property:

let section = NSCollectionLayoutSection(group: group)
    
let sectionHeader = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize,
                                                               elementKind: ElementKind.sectionHeader,
                                                                 alignment: .top)
let sectionFooter = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize,
                                                               elementKind: ElementKind.sectionFooter,
                                                                 alignment: .bottom)
    
section.boundarySupplementaryItems = [sectionHeader, sectionFooter]

Topics

Creating a Boundary Supplementary Item

init(layoutSize: NSCollectionLayoutSize, elementKind: String, alignment: NSRectAlignment)

Creates a boundary supplementary item of the specified size, with a string to identify the element kind and an alignment relative to a section or layout.

init(layoutSize: NSCollectionLayoutSize, elementKind: String, alignment: NSRectAlignment, absoluteOffset: CGPoint)

Creates a boundary supplementary item of the specified size, with a string to identify the element kind and an alignment relative to a section or layout at an absolute offset.

Specifying Scrolling Behavior

var pinToVisibleBounds: Bool

A Boolean value that indicates whether a header or footer is pinned to the top or bottom visible boundary of the section or layout it's attached to.

Specifying Position

var offset: CGPoint

The floating-point value of the boundary supplementary item's offset from the section or layout it's attached to.

var alignment: NSRectAlignment

The alignment of the boundary supplementary item relative to the section or layout it's attached to.

var extendsBoundary: Bool

A Boolean value that indicates whether a boundary supplementary item extends the content area of the section or layout it's attached to.

See Also

Appearance

class NSCollectionLayoutAnchor

An object that defines how to attach a supplementary item to an item in a collection view.

class NSCollectionLayoutSupplementaryItem

An object used to add an extra visual decoration, such as a badge or a frame, to an item in a collection view.

class NSCollectionLayoutDecorationItem

An object used to add a background to a section of a collection view.