Class

UICollectionViewLayoutAttributes

A layout object that manages the layout-related attributes for a given item in a collection view.

Declaration

@interface UICollectionViewLayoutAttributes : NSObject

Overview

Layout objects create instances of this class when asked to do so by the collection view. In turn, the collection view uses the layout information to position cells and supplementary views inside its bounds.

Subclassing Notes

In most cases, you use this class as-is. If you want to supplement the base layout attributes with custom layout attributes, you can subclass and define whatever properties you want to store the additional layout data. Because layout attribute objects may be copied by the collection view, make sure your subclass conforms to the NSCopying protocol by implementing any methods appropriate for copying your custom attributes to new instances of your subclass. In addition to defining your subclass, your UICollectionReusableView objects need to implement the applyLayoutAttributes: method so that they can apply any custom attributes at layout time.

If you subclass and implement any custom layout attributes, you must also override the inherited isEqual: method to compare the values of your properties. In iOS 7 and later, the collection view does not apply layout attributes if those attributes have not changed. It determines whether the attributes have changed by comparing the old and new attribute objects using the isEqual: method. Because the default implementation of this method checks only the existing properties of this class, you must implement your own version of the method to compare any additional properties. If your custom properties are all equal, call super and return the resulting value at the end of your implementation.

Topics

Creating Layout Attributes

+ layoutAttributesForCellWithIndexPath:

Creates and returns a layout attributes object that represents a cell with the specified index path.

+ layoutAttributesForSupplementaryViewOfKind:withIndexPath:

Creates and returns a layout attributes object that represents the specified supplementary view.

+ layoutAttributesForDecorationViewOfKind:withIndexPath:

Creates and returns a layout attributes object that represents the specified decoration view.

Identifying the Referenced Item

indexPath

The index path of the item in the collection view.

representedElementCategory

The type of the item.

representedElementKind

The layout-specific identifier for the target view.

Accessing the Layout Attributes

frame

The frame rectangle of the item.

bounds

The bounds of the item.

center

The center point of the item.

size

The size of the item.

transform3D

The 3D transform of the item.

transform

The affine transform of the item.

alpha

The transparency of the item.

zIndex

Specifies the item’s position on the z axis.

hidden

Determines whether the item is currently displayed.

Constants

UICollectionElementCategory

Constants specifying the type of view.

Relationships

Inherits From

See Also

Layouts

Customizing Collection View Layouts

Customize a view layout by changing the size of cells in the flow or implementing a mosaic style.

UICollectionViewLayout

An abstract base class for generating layout information for a collection view.

UICollectionViewFlowLayout

A concrete layout object that organizes items into a grid with optional header and footer views for each section.

UICollectionViewTransitionLayout

A special type of layout object that lets you implement behaviors when changing from one layout to another in your collection view.

Compositional Layout Objects

Compose your layout from a set of objects that support more adaptive and flexible arragnements.

Using Collection View Compositional Layouts and Diffable Data Sources

Learn how to bring complex, high-performance layouts to your app, and simplify updating and managing your UI.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software