iOS Developer Library

Developer

UIKit Framework Reference UICollectionViewCell Class Reference

Options
Deployment Target:

On This Page
Language:

UICollectionViewCell

A UICollectionViewCell object presents the content for a single data item when that item is within the collection view’s visible bounds. You can use this class as-is or subclass it to add additional properties and methods. The layout and presentation of cells is managed by the collection view and its corresponding layout object.

To configure the appearance of your cell, add the views needed to present the data item’s content as subviews to the view in the contentView property. Do not directly add subviews to the cell itself. The cell manages multiple layers of content, of which the content view is only one. In addition to the content view, the cell manages two background views that display the cell in its selected and unselected states.

You typically do not create instances of this class yourself. Instead, you register your specific cell subclass (or a nib file containing a configured instance of your class) with the collection view object. When you want a new instance of your cell class, call the dequeueReusableCellWithReuseIdentifier:forIndexPath: method of the collection view object to retrieve one.

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later.
  • The main view to which you add your cell’s custom content. (read-only)

    Declaration

    Swift

    var contentView: UIView { get }

    Objective-C

    @property(nonatomic, readonly) UIView *contentView

    Discussion

    When configuring a cell, you add any custom views representing your cell’s content to this view. The cell object places the content in this view in front of any background views.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The view that is displayed behind the cell’s other content.

    Declaration

    Swift

    var backgroundView: UIView?

    Objective-C

    @property(nonatomic, retain) UIView *backgroundView

    Discussion

    Use this property to assign a custom background view to the cell. The background view is placed behind the content view and its frame is automatically adjusted so that it fills the bounds of the cell.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The view that is displayed just above the background view when the cell is selected.

    Declaration

    Swift

    var selectedBackgroundView: UIView!

    Objective-C

    @property(nonatomic, retain) UIView *selectedBackgroundView

    Discussion

    You can use this view to give the cell a custom appearance when it is selected. When the cell is selected, this view is layered above the backgroundView and behind the contentView.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • selected selected Property

    The selection state of the cell.

    Declaration

    Swift

    var selected: Bool

    Objective-C

    @property(nonatomic, getter=isSelected) BOOL selected

    Discussion

    This property manages the selection state of the cell only. The default value of this property is NOfalse, which indicates that the cell is not selected.

    You typically do not set the value of this property directly. Changing the value of this property programmatically does not change the appearance of the cell. The preferred way to select the cell and highlight it is to use the selection methods of the collection view object.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The highlight state of the cell.

    Declaration

    Swift

    var highlighted: Bool

    Objective-C

    @property(nonatomic, getter=isHighlighted) BOOL highlighted

    Discussion

    This property manages the highlight state of the cell only. The default value of this property is NOfalse, which indicates that the cell is not highlighted.

    You typically do not set the value of this property directly. Instead, the preferred way to select the cell and highlight it is to use the selection methods of the collection view object.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.