<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UICollectionViewLayout/layoutAttributesForElements(in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UICollectionViewLayout(im)layoutAttributesForElementsInRect:"
  },
  "title" : "layoutAttributesForElements(in:)"
}
-->

# layoutAttributesForElements(in:)

Retrieves the layout attributes for all of the cells and views in the specified rectangle.

```
func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
```

## Parameters

`rect`

The rectangle (specified in the collection view’s coordinate system) containing the target views.

## Return Value

An array of [`UICollectionViewLayoutAttributes`](/documentation/UIKit/UICollectionViewLayoutAttributes) objects representing the layout information for the cells and views. The default implementation returns `nil`.

## Discussion

Subclasses must override this method and use it to return layout information for all items whose view intersects the specified rectangle. Your implementation should return attributes for all visual elements, including cells, supplementary views, and decoration views.

When creating the layout attributes, always create an attributes object that represents the correct element type (cell, supplementary, or decoration). The collection view differentiates between attributes for each type and uses that information to make decisions about which views to create and how to manage them.

---

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)