Class

UICollectionViewCompositionalLayoutConfiguration

An object that defines scroll direction, section spacing, and headers or footers for the layout.

Declaration

class UICollectionViewCompositionalLayoutConfiguration : NSObject

Overview

You use a layout configuration to modify a collection view layout's default scroll direction, add extra spacing between each section of the layout, and add headers or footers to the entire layout.

You can pass in this configuration when creating a UICollectionViewCompositionalLayout, or you can set the configuration property on an existing layout. If you modify the configuration on an existing layout, the system invalidates the layout so that it will be updated with the new configuration.

let headerFooterSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                             heightDimension: .estimated(44))

let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize,
                                                        elementKind: "header",
                                                          alignment: .top)
let footer = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize,
                                                        elementKind: "footer",
                                                          alignment: .bottom)

let config = UICollectionViewCompositionalLayoutConfiguration()
config.interSectionSpacing = 20
config.scrollDirection = .horizontal
config.boundarySupplementaryItems = [header, footer]

Topics

Specifying Scroll Direction

var scrollDirection: UICollectionView.ScrollDirection

The axis that the content in the collection view layout scrolls along.

Configuring Spacing

var interSectionSpacing: CGFloat

The amount of space between the sections in the layout.

Configuring Additional Views

var boundarySupplementaryItems: [NSCollectionLayoutBoundarySupplementaryItem]

An array of the supplementary items that are associated with the boundary edges of the entire layout, such as global headers and footers.

Relationships

Inherits From

See Also

Configuration

typealias UICollectionViewCompositionalLayoutSectionProvider

A closure that creates and returns each of the layout's sections.

protocol NSCollectionLayoutEnvironment

A protocol used to provide information about the layout's container and environment traits, such as size classes and display scale factor.