<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewLayoutAttributes",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCollectionViewLayoutAttributes"
  },
  "title" : "NSCollectionViewLayoutAttributes"
}
-->

# NSCollectionViewLayoutAttributes

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

```
@MainActor class NSCollectionViewLayoutAttributes
```

## Overview

During the layout, the layout object creates instances of [`NSCollectionViewLayoutAttributes`](/documentation/AppKit/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 <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/init()> method with no parameters to initialize your subclass.
- Implement support for the <doc://com.apple.documentation/documentation/Foundation/NSCopying> protocol. The collection view caches layout attribute objects for later use.
- Override the inherited <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/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 <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/isEqual(_:)> method.

In addition to defining your `NSCollectionViewLayoutAttributes` subclass, override the [`layoutAttributesClass`](/documentation/AppKit/NSCollectionViewLayout/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.

## Topics

### Creating Layout Attributes

[`init(forItemWith:)`](/documentation/AppKit/NSCollectionViewLayoutAttributes/init(forItemWith:))

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

[`init(forSupplementaryViewOfKind:with:)`](/documentation/AppKit/NSCollectionViewLayoutAttributes/init(forSupplementaryViewOfKind:with:))

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

[`init(forDecorationViewOfKind:with:)`](/documentation/AppKit/NSCollectionViewLayoutAttributes/init(forDecorationViewOfKind:with:))

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

[`init(forInterItemGapBefore:)`](/documentation/AppKit/NSCollectionViewLayoutAttributes/init(forInterItemGapBefore:))

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

[`NSCollectionView.DecorationElementKind`](/documentation/AppKit/NSCollectionView/DecorationElementKind)

### Identifying the Element

[`representedElementCategory`](/documentation/AppKit/NSCollectionViewLayoutAttributes/representedElementCategory)

The type of the element.

[`indexPath`](/documentation/AppKit/NSCollectionViewLayoutAttributes/indexPath)

The index path of the element.

[`representedElementKind`](/documentation/AppKit/NSCollectionViewLayoutAttributes/representedElementKind)

The identifier for specific elements of your collection view interface.

[`elementKindInterItemGapIndicator`](/documentation/AppKit/NSCollectionView/elementKindInterItemGapIndicator)

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

[`elementKindSectionFooter`](/documentation/AppKit/NSCollectionView/elementKindSectionFooter)

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

[`elementKindSectionHeader`](/documentation/AppKit/NSCollectionView/elementKindSectionHeader)

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

### Accessing the Layout Attributes

[`frame`](/documentation/AppKit/NSCollectionViewLayoutAttributes/frame)

The frame rectangle of the element.

[`size`](/documentation/AppKit/NSCollectionViewLayoutAttributes/size)

The size of the element.

[`alpha`](/documentation/AppKit/NSCollectionViewLayoutAttributes/alpha)

The transparency of the element.

[`isHidden`](/documentation/AppKit/NSCollectionViewLayoutAttributes/isHidden)

A Boolean value indicating whether the element is hidden.

[`zIndex`](/documentation/AppKit/NSCollectionViewLayoutAttributes/zIndex)

The element’s position on the z axis.

### Constants

[`NSCollectionElementCategory`](/documentation/AppKit/NSCollectionElementCategory)

Constants specifying the type of element in the collection view.

[Inter-Item Gap Support](/documentation/AppKit/inter-item-gap-support)

Constant for supporting inter-item gaps.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)