An object that contains layout-related attributes for an element in a collection view.


@interface NSCollectionViewLayoutAttributes : NSObject


During the layout, the layout object creates instances of NSCollectionViewLayoutAttributes for each element displayed in the collection view. The layout attributes describe the position of an element and other information such as its alpha and position on the z axis. The collection view later applies the layout attributes to the onscreen elements.

The only time you interact with layout attribute objects is when you implement a custom layout, and the interactions are straightforward. When asked for layout attributes for a specific element, your layout object uses the methods of this class to create an appropriate instance of the class based on the type of the requested element. It then configures the properties of the object and returns it to the requester.

Subclassing Notes

If you implement a custom layout object and your layout object requires additional attributes, you can subclass NSCollectionViewLayoutAttributes and add custom properties to your subclass. In your subclass, be sure to do the following:

  • Provide an init method with no parameters to initialize your subclass.

  • Implement support for the NSCopying protocol. The collection view caches layout attribute objects for later use.

  • Override the inherited isEqual: method to perform any relevant equality checks.

Supporting equality checks is important because of how the collection view manages layout attributes. As an optimization, the collection view applies layout attributes only when they change. When the layout object returns a layout attributes object, the collection view checks to see if the new attributes are equal to any cached attributes. Therefore, if you want to include any new properties in the equality check, you must override the isEqual: method.

In addition to defining your NSCollectionViewLayoutAttributes subclass, override the layoutAttributesClass method of your layout object. That method is a funnel point for creating new layout attribute objects. Returning your custom class from that method ensures that the correct class is instantiated.


Creating Layout Attributes

+ layoutAttributesForItemWithIndexPath:

Creates and returns a layout attributes object for the item at the specified index path.

+ layoutAttributesForSupplementaryViewOfKind:withIndexPath:

Creates and returns a layout attributes object for a supplementary view based on the specified information.

+ layoutAttributesForDecorationViewOfKind:withIndexPath:

Creates and returns a layout attributes object for a decoration view based on the specified information.

+ layoutAttributesForInterItemGapBeforeIndexPath:

Creates and returns a layout attributes object for an inter-item gap view at the specified index path.

Identifying the Element


The type of the element.


The index path of the element.


The identifier for specific elements of your collection view interface.


The element kind string assigned to the attributes object when it represents an inter-item gap.


A supplementary view that acts as a footer for a given section.


A supplementary view that acts as a header for a given section.

Accessing the Layout Attributes


The frame rectangle of the element.


The size of the element.


The transparency of the element.


A Boolean value indicating whether the element is hidden.


The element’s position on the z axis.



Constants specifying the type of element in the collection view.

Inter-Item Gap Support

Constant for supporting inter-item gaps.


Inherits From

Conforms To

See Also


Using Collection View Compositional Layouts and Diffable Data Sources

Bring complex, high-performance layouts to your app, and simplify updating and managing your user interface.


A layout that organizes items into a flexible and configurable arrangement.


A set of methods that a delegate implements to provide layout information to a flow layout object in a collection view.


A layout that displays a single section of items in a row and column grid.


An object that implements custom behaviors when changing from one layout to another in a collection view.


An abstract base class that you subclass and use to generate layout information for a collection view.


A layout object that lets you combine items in highly adaptive and flexible visual arrangements.


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


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


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