Use UICollectionViewFlowLayout and Let It Rotate!

Going around

Steven Curtis
6 min readJun 1, 2023
Photo by Farhan Azam on Unsplash

Before we start

Difficulty: Beginner | Easy | Normal | Challenging

Keywords and Terminology:

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

UICollectionViewCell: The on-screen cell for the UICollectionView type

UICollectionViewFlowLayout: A layout object that organizes items into a grid with optional header and footer views for each section

Rather than having a simple grid where you use UICollectionViewFlowLayout alone, you can subclass UICollectionViewLayout to make a more sophisticated layout.

This article helps you to create the most simple UICollectionViewFlowLayout programatically, and uses explicitly defining cell sizes so this is something to build on for more complex layouts.

Why

Apple have given us the standard UICollectionViewFlowLayout, and this works fantastically for most uses of UICollectionView where grids are needed.

This might be done (in the example code this is in loadView by using the following code:

let layout: UICollectionViewFlowLayout =…

--

--