<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewElement/preferredLayoutAttributesFitting(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSCollectionViewElement(im)preferredLayoutAttributesFittingAttributes:"
  },
  "title" : "preferredLayoutAttributesFitting(_:)"
}
-->

# preferredLayoutAttributesFitting(_:)

Asks your element if it wants to modify any layout attributes before they are applied.

```
@MainActor optional func preferredLayoutAttributesFitting(_ layoutAttributes: NSCollectionViewLayoutAttributes) -> NSCollectionViewLayoutAttributes
```

## Parameters

`layoutAttributes`

The attributes provided by the layout object. These attributes represent the values that the layout object intends to apply to the element.

## Return Value

The final attributes to apply to the element.

## Discussion

The default implementation of this method returns the same attributes that are in the `layoutAttributes` parameter. You can override this method in subclasses and use it to return a different set of attributes. If you override this method, call `super` first to give the system the opportunity to make changes, then modify the returned attributes.

### Special Considerations

In OS X 10.11, this method is never called.

---

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)