Collection Views

Display nested views using a configurable and highly customizable layout.

Overview

A collection view manages an ordered set of content, such as the grid of photos in the Photos app, and presents it visually.

Screenshot of the Photos app on iOS showing a grid of photos displayed in the Days view.

Collection views are a collaboration between many different objects, including:

  • Cells. A cell provides the visual representation for each piece of your content.

  • Layouts. A layout defines the visual arrangement of the content in the collection view.

  • Your data source object. This object adopts the UICollectionViewDataSource protocol and provides the data for the collection view.

  • Your delegate object. This object adopts the UICollectionViewDelegate protocol and manages user interactions with the collection view's contents, like selection and highlighting.

  • Collection view controller. You typically use a UICollectionViewController object to manage a collection view. You can use other view controllers too, but a collection view controller is required for some collection-related features to work.

Topics

View

class UICollectionView

An object that manages an ordered collection of data items and presents them using customizable layouts.

class UICollectionViewController

A view controller that specializes in managing a collection view.

Data

protocol UICollectionViewDataSource

The methods adopted by the object you use to manage data and provide cells for a collection view.

protocol UICollectionViewDataSourcePrefetching

A protocol that provides advance warning of the data requirements for a collection view, allowing the triggering of asynchronous data load operations.

Cells

class UICollectionViewCell

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

class UICollectionReusableView

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

Layouts

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.

Layouts

Arrange your collection view content in a highly configurable layout.

Selection Management

Changing the Appearance of Selected and Highlighted Cells

Provide visual feedback to the user about the state of a cell and the transition between states.

Selecting Multiple Items with a Two-Finger Pan Gesture

Accelerate user selection of multiple items using the multiselect gesture on table and collection views.

Drag and Drop

Supporting Drag and Drop in Collection Views

Initiate drags and handle drops from a collection view.

protocol UICollectionViewDragDelegate

The interface for initiating drags from a collection view.

protocol UICollectionViewDropDelegate

The interface for handling drops in a collection view.

protocol UICollectionViewDropCoordinator

An interface for coordinating your custom drop-related actions with the collection view.

class UICollectionViewDropPlaceholder

A placeholder for an item dropped on a collection view.

class UICollectionViewDropProposal

Your proposed solution for handling a drop in a collection view.

protocol UICollectionViewDropItem

The data associated with an item being dropped into the collection view.

protocol UICollectionViewDropPlaceholderContext

An object that contains information about a placeholder in the collection view.

protocol UIDataSourceTranslating

An advanced interface for managing a data source object.

class UICollectionViewPlaceholder

A placeholder for an item dragged or dropped on a collection view.

See Also

Container Views

Table Views

Display data in a single column of customizable rows.

class UIStackView

A streamlined interface for laying out a collection of views in either a column or a row.

class UIScrollView

A view that allows the scrolling and zooming of its contained views.