A single data item when that item is within the collection view’s visible bounds.


class UICollectionViewCell : UICollectionReusableView


You can use UICollectionViewCell 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 dequeueReusableCell(withReuseIdentifier:for:) method of the collection view object to retrieve one.


Accessing the Cell’s Views

var contentView: UIView

The main view to which you add your cell’s custom content.

var backgroundView: UIView?

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

var selectedBackgroundView: UIView?

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

Managing the Cell’s State

var isSelected: Bool

The selection state of the cell.

var isHighlighted: Bool

The highlight state of the cell.

Managing Drag State Changes

func dragStateDidChange(UICollectionViewCell.DragState)

Called when the drag state of the cell changes.

enum UICollectionViewCell.DragState

Constants indicating the current state of the drag operation.

See Also


class UICollectionReusableView

A view that defines the behavior for all cells and supplementary views presented by a collection view.