iOS Developer Library

Developer

UIKit Framework Reference UICollectionReusableView Class Reference

Options
Deployment Target:

On This Page
Language:

UICollectionReusableView

Inherits From


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later

The UICollectionReusableView class defines the behavior for all cells and supplementary views presented by a collection view. Reusable views are so named because the collection view places them on a reuse queue rather than deleting them when they are scrolled out of the visible bounds. Such a view can then be retrieved and repurposed for a different set of content.

Subclassing Notes

This class is intended to be subclassed. Most methods defined by this class have minimal or no implementations. You are not required to override any of the methods but can do so in cases where you want to respond to changes in the view’s usage or layout.

  • A string that identifies the purpose of the view. (read-only)

    Declaration

    Swift

    var reuseIdentifier: String { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSString *reuseIdentifier

    Discussion

    The collection view identifies and queues reusable views using their reuse identifiers. The collection view sets this value when it first creates the view, and the value cannot be changed later. When your data source is prompted to provide a given view, it can use the reuse identifier to dequeue a view of the appropriate type.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

  • Performs any clean up necessary to prepare the view for use again.

    Declaration

    Swift

    func prepareForReuse()

    Objective-C

    - (void)prepareForReuse

    Discussion

    The default implementation of this method does nothing. However, when overriding this method, it is recommended that you call super anyway. Subclasses such as UICollectionViewCell override this method and use it to perform relevant actions. So if your subclass descends from UICollectionViewCell or some other intermediate class, calling super ensures that your class gets the parent’s behavior.

    When a view is dequeued for use, this method is called before the corresponding dequeue method returns the view to your code. Subclasses can override this method and use it to reset properties to their default values and generally make the view ready to use again. You should not use this method to assign any new data to the view. That is the responsibility of your data source object.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

  • Gives the cell a chance to modify the attributes provided by the layout object.

    Declaration

    Swift

    func preferredLayoutAttributesFittingAttributes(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes!

    Objective-C

    - (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes

    Parameters

    layoutAttributes

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

    Return Value

    The final attributes to apply to the cell.

    Discussion

    The default implementation of this method adjusts the size values to accommodate changes made by a self-sizing cell. Subclasses can override this method and use it to adjust other layout attributes too. If you override this method and want the cell size adjustments, call super first and make your own modifications to the returned attributes.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later

  • Applies the specified layout attributes to the view.

    Declaration

    Swift

    func applyLayoutAttributes(_ layoutAttributes: UICollectionViewLayoutAttributes!)

    Objective-C

    - (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes

    Parameters

    layoutAttributes

    The layout attributes to apply.

    Discussion

    The default implementation of this method does nothing.

    If the layout object supports custom layout attributes, you can use this method to apply those attributes to the view. In such a case, the layoutAttributes parameter should contain an instance of a subclass of UICollectionViewLayoutAttributes. You do not need to override this method to support the standard layout attributes of the UICollectionViewLayoutAttributes class. The collection view applies those attributes automatically.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

  • Tells your view that the layout object of the collection view is about to change.

    Declaration

    Swift

    func willTransitionFromLayout(_ oldLayout: UICollectionViewLayout, toLayout newLayout: UICollectionViewLayout)

    Objective-C

    - (void)willTransitionFromLayout:(UICollectionViewLayout *)oldLayout toLayout:(UICollectionViewLayout *)newLayout

    Parameters

    oldLayout

    The current layout object associated with the collection view.

    newLayout

    The new layout object that is about to be applied to the collection view.

    Discussion

    The default implementation of this method does nothing. Subclasses can override this method and use it to prepare for the change in layouts.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

  • Tells your view that the layout object of the collection view changed.

    Declaration

    Swift

    func didTransitionFromLayout(_ oldLayout: UICollectionViewLayout, toLayout newLayout: UICollectionViewLayout)

    Objective-C

    - (void)didTransitionFromLayout:(UICollectionViewLayout *)oldLayout toLayout:(UICollectionViewLayout *)newLayout

    Parameters

    oldLayout

    The collection view’s previous layout object.

    newLayout

    The current layout object associated with the collection view.

    Discussion

    The default implementation of this method does nothing. Subclasses can override this method and use it to finalize any behaviors associated with the change in layouts.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later