Class

NSCollectionLayoutDimension

An individual dimension of an item's size (width or height) in a collection view.

Declaration

@interface NSCollectionLayoutDimension : NSObject

Overview

Each item in a collection view has an explicit width dimension and height dimension, which combine to define the item's size (NSCollectionLayoutSize).

You can express an item's dimensions using an absolute, estimated, or fractional value.

Use an absolute value to specify exact dimensions, like a 44 x 44 point square:

let absoluteSize = NSCollectionLayoutSize(widthDimension: .absolute(44),
                                         heightDimension: .absolute(44))

Use an estimated value if the size of your content might change at runtime, such as when data is loaded or in response to a change in system font size. You provide an initial estimated size and the system computes the actual value later.

let estimatedSize = NSCollectionLayoutSize(widthDimension: .estimated(200),
                                          heightDimension: .estimated(100))

Use a fractional value to define a value that's relative to a dimension of the item's container. This option simplifies specifying aspect ratios. For example, the following item has a width and a height that are both equal to 20% of its container's width, creating a square that grows and shrinks as the size of its container changes.

let fractionalSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.2),
                                           heightDimension: .fractionalWidth(0.2))

Topics

Creating a Dimension

+ absoluteDimension:

Creates a dimension with an absolute point value.

+ estimatedDimension:

Creates a dimension with an estimated point value.

+ fractionalHeightDimension:

Creates a dimension that is computed as a fraction of the height of the containing group.

+ fractionalWidthDimension:

Creates a dimension that is computed as a fraction of the width of the containing group.

Getting the Dimension Value

dimension

The floating-point value of the dimension.

Getting the Dimension Type

isAbsolute

A Boolean value that indicates whether the dimension is expressed as an absolute value.

isEstimated

A Boolean value that indicates whether the dimension is expressed as an estimated value.

isFractionalHeight

A Boolean value that indicates whether the dimension is expressed as a fraction of its container's height.

isFractionalWidth

A Boolean value that indicates whether the dimension is expressed as a fraction of its container's width.

Relationships

Inherits From

Conforms To

See Also

Size and Spacing

NSCollectionLayoutSize

The width and the height of an item in a collection view.

NSCollectionLayoutSpacing

An object that defines the space between or around items in a collection view.

NSCollectionLayoutEdgeSpacing

An object that defines the space around the edges of items in a collection view.

NSCollectionLayoutContainer

A protocol used to provide information about the size and content insets of a layout's container.