UICollectionViewLayoutAttributes Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 6.0 and later. |
| Declared in | UICollectionViewLayout.h |
Overview
An UICollectionViewLayoutAttributes object manages the layout-related attributes for a given item in a collection view. 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.
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.
Tasks
Creating Layout Attributes
-
+ layoutAttributesForCellWithIndexPath: -
+ layoutAttributesForSupplementaryViewOfKind:withIndexPath: -
+ layoutAttributesForDecorationViewOfKind:withIndexPath:
Identifying the Referenced Item
-
indexPathproperty -
representedElementCategoryproperty -
representedElementKindproperty
Accessing the Layout Attributes
Properties
alpha
The transparency of the item.
Discussion
Possible values are between 0.0 (transparent) and 1.0 (opaque). The default is 1.0.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hcenter
The center point of the item.
Discussion
The center point is specified in the coordinate system of the collection view. Setting the value of this property also updates the origin of the rectangle in the frame property.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hframe
The frame rectangle of the item.
Discussion
The frame rectangle is measured in points and specified in the coordinate system of the collection view. Setting the value of this property also sets the values of the center and size properties.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hhidden
Determines whether the item is currently displayed.
Discussion
The default value of this property is NO. As an optimization, the collection view might not create the corresponding view if this property is set to YES.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hindexPath
The index path of the item in the collection view.
Discussion
The index path contains the index of the section and the index of the item within that section. These two values uniquely identify the position of the corresponding item in the collection view.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hrepresentedElementCategory
The type of the item. (read-only)
Discussion
You can use the value in this property to distinguish whether the layout attributes are intended for a cell, supplementary view, or decoration view.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hrepresentedElementKind
The layout-specific identifier for the target view. (read-only)
Discussion
You can use the value in this property to identify the specific purpose of the supplementary or decoration view associated with the attributes. This property is nil if the representedElementCategory property contains the value UICollectionElementCategoryCell.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hsize
The size of the item.
Discussion
Setting the value of this property also changes the size of the rectangle returned by the frame property.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.htransform3D
The transform of the item.
Discussion
Setting the value of this property affects the rectangle returned by the frame property.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hzIndex
Specifies the item’s position on the z axis.
Discussion
The default value of this property is 0.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hClass Methods
layoutAttributesForCellWithIndexPath:
Creates and returns a layout attributes object that represents a cell with the specified index path.
Parameters
- indexPath
The index path of the cell.
Return Value
A new layout attributes object whose precise type matches the type of the class used to call this method.
Discussion
Use this method to create a layout attributes object for a cell in the collection view. Cells are the main type of view presented by a collection view. The index path for a cell typically includes both a section index and an item index for locating the cell’s contents in the collection view’s data source.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hlayoutAttributesForDecorationViewOfKind:withIndexPath:
Creates and returns a layout attributes object that represents the specified decoration view.
Parameters
- decorationViewKind
The kind identifier for the specified decoration view.
- indexPath
An index path related to the decoration view.
Return Value
A new layout attributes object whose precise type matches the type of the class used to call this method.
Discussion
Use this method to create a layout attributes object for a decoration view in the collection view. Decoration views are a type of supplementary view but do not present data that is managed by the collection view’s data source. Instead, they mostly present visual adornments for a section or for the entire collection view.
It is up to you to decide how to use the indexPath parameter to identify a given decoration view. Typically, you use the decorationViewKind parameter to identify the type of the decoration view and the indexPath information to distinguish between different instances of that view.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hlayoutAttributesForSupplementaryViewOfKind:withIndexPath:
Creates and returns a layout attributes object that represents the specified supplementary view.
Parameters
- elementKind
A string that identifies the type of supplementary view.
- indexPath
The index path of the view.
Return Value
A new layout attributes object whose precise type matches the type of the class used to call this method.
Discussion
Use this method to create a layout attributes object for a supplementary view in the collection view. Like cells, supplementary views present data that is managed by the collection view’s data source. But unlike cells, supplementary views are typically designed for a special purpose. For example, header and footer views are laid out differently than cells and can be provided for individual sections or for the collection view as a whole.
It is up to you to decide how to use the indexPath parameter to identify a given supplementary view. Typically, you use the elementKind parameter to identify the type of the supplementary view and the indexPath information to distinguish between different instances of that view.
Availability
- Available in iOS 6.0 and later.
Declared In
UICollectionViewLayout.hConstants
UICollectionElementCategory
Constants specifying the type of view.
typedef enum {
UICollectionElementCategoryCell,
UICollectionElementCategorySupplementaryView,
UICollectionElementCategoryDecorationView
} UICollectionElementCategory;
Constants
UICollectionElementCategoryCellThe view is a cell.
Available in iOS 6.0 and later.
Declared in
UICollectionViewLayout.h.UICollectionElementCategorySupplementaryViewThe view is a supplementary view.
Available in iOS 6.0 and later.
Declared in
UICollectionViewLayout.h.UICollectionElementCategoryDecorationViewThe view is a decoration view.
Available in iOS 6.0 and later.
Declared in
UICollectionViewLayout.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)