Class

NSCollectionLayoutDecorationItem

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

Declaration

@interface NSCollectionLayoutDecorationItem : NSCollectionLayoutItem

Overview

Each type of decoration 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 a background to a section by setting that section's decorationItems property:

let sectionBackground = NSCollectionLayoutDecorationItem.background(
        elementKind: ElementKind.background)

section.decorationItems = [sectionBackground]

let layout = UICollectionViewCompositionalLayout(section: section)
layout.register(
    SectionBackgroundDecorationView.self,
    forDecorationViewOfKind: ElementKind.background)
return layout

Topics

Creating a Background

+ backgroundDecorationItemWithElementKind:

Creates a section background with a string to identify the element kind.

Getting the Element Kind

elementKind

A string that identifies the type of decoration item.

Specifying Stacking Order

zIndex

The vertical stacking order of the decoration item in relation to other items in the section.

Relationships

Conforms To

See Also

Appearance

NSCollectionLayoutAnchor

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

NSCollectionLayoutSupplementaryItem

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

NSCollectionLayoutBoundarySupplementaryItem

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