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


class NSCollectionLayoutItem : NSObject


An item is a blueprint for how to size, space, and arrange an individual piece of content in your collection view. An item represents a single view that's rendered onscreen. Generally, an item is a cell, but items can be supplementary views like headers, footers, and other decorations.

For example, in the Photos app, an item might represent a single photo. In the App Store app, an item might be a cell displaying information about an individual app in a list of featured apps, such as the app icon, app name, tagline, and download button.

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 types of items are highlighted and labeled as items.

Each item specifies its own size in terms of a width dimension and a height dimension. Items can express their dimensions relative to their container, as an absolute value, or as an estimated value that might change at runtime, like in response to a change in system font size. For more information, see NSCollectionLayoutDimension.

You combine items into groups that determine how those items are arranged in relation to each other. For more information, see NSCollectionLayoutGroup.


Creating an Item

init(layoutSize: NSCollectionLayoutSize)

Creates an item of the specified size.

init(layoutSize: NSCollectionLayoutSize, supplementaryItems: [NSCollectionLayoutSupplementaryItem])

Creates an item of the specified size with an array of supplementary items to attach to the item.

Getting an Item's Size

var layoutSize: NSCollectionLayoutSize

The item's size expressed in width and height dimensions.

Getting Supplementary Items

var supplementaryItems: [NSCollectionLayoutSupplementaryItem]

An array of the supplementary items attached to the item.

Configuring Spacing and Insets

var edgeSpacing: NSCollectionLayoutEdgeSpacing?

The amount of space added around the boundaries of the item between other items and this item's container.

var contentInsets: NSDirectionalEdgeInsets

The amount of space added around the content of the item to adjust its final size after its position is computed.


Inherits From

See Also


class NSCollectionLayoutGroup

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

class NSCollectionLayoutSection

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