A container that combines a set of groups into distinct visual groupings.


class NSCollectionLayoutSection : NSObject


A collection view layout has one or more sections. Sections provide a way to separate the layout into distinct pieces.

Each section can have the same layout or a different layout than the other sections in the collection view. A section's layout is determined by the properties of the group (NSCollectionLayoutGroup) that's used to create the section.

In the Photos app, each section in the Years page uses the same layout. In the App Store, the Apps page displays several sections with different content arrangements.

Schematic representation of the App Store app on iOS, showing a collection view with a compositional layout. The layout is composed of two horizontally-scrolling sections that have different layouts. The top section shows one group with one item visible onscreen, with other groups peeking in from the sides of the screen. The bottom section shows one group that's a column of three cells, each of those cells being an item. The two different sections are highlighted and labeled as sections.

Each section can have its own background, header, and footer to distinguish it from other sections.


Creating a Section

init(group: NSCollectionLayoutGroup)

Creates a section containing the specified group.

Specifying Scrolling Behavior

var orthogonalScrollingBehavior: UICollectionLayoutSectionOrthogonalScrollingBehavior

The section's scrolling behavior in relation to the main layout axis.

Configuring Section Spacing

var interGroupSpacing: CGFloat

The amount of space between the groups in the section.

var contentInsets: NSDirectionalEdgeInsets

The amount of space between the content of the section and its boundaries.

var supplementariesFollowContentInsets: Bool

A Boolean value that indicates whether the section's supplementary items follow the content insets specified for the section.

Configuring Additional Views

var boundarySupplementaryItems: [NSCollectionLayoutBoundarySupplementaryItem]

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

var decorationItems: [NSCollectionLayoutDecorationItem]

An array of the decoration items that are anchored to the section, such as background decoration views.

Rendering Items

var visibleItemsInvalidationHandler: NSCollectionLayoutSectionVisibleItemsInvalidationHandler?

A closure called before each layout cycle to allow modification of the items in the section immediately before they are displayed.


Inherits From

See Also


class NSCollectionLayoutItem

The most basic component of a collection view's layout.

class NSCollectionLayoutGroup

A container for a set of items that lays out the items along a path.