Custom CollectionView in Swift 5

A step by step guide to creating a customized collection view

Julie Elise
Level Up Coding
Published in
4 min readFeb 2, 2021

--

When developing an iOS app, you may find yourself needing to customize layouts and populate tables with dynamic and customizable content. The UICollectionView is a popular UI element for presenting a collection of items in a customizable layout. This article presents a step by step guide to creating a UICollectionView and UICollectionViewCell. Note that this article assumes basic knowledge of Xcode, Swift, and the UICollectionView.

Create a new iOS app project

Select the Main storyboard from the file browser. Add a CollectionView by pressing command shift L to open the storyboard widget window. Drag the collectionView onto the main view controller.

Add constraints to the UICollectionView widget to ensure that the widget fills the screen on all devices.

The foundation is now set up in the storyboard. In order to customize the collectionView and collectionView cell, you’ll need to create custom classes for each widget type and assign these newly created classes to the respective widgets in the storyboard.

Create a UICollectionView file

  1. Create a new Cocoa Touch Class file.

2. Enter a name for the class. The subclass must be set to UICollectionView.

--

--