Working with UICollectionView
UICollectionView
is a very handy and awesome view when it comes to dealing with grid layout. Collection view helps you create a grid layout (2D cells) easily without hassle. Collection view is just a scrollable view that lays out multiple cells in a grid layout. So, to create a collection view, you have to specify a data source and delegate exactly like UITableView
. Besides that, you need to specify how the layout of your cells will appear. iOS provides you with an abstract class-UICollectionViewLayout
-which should be subclassed to customize how the content will be managed. You can create your own custom layouts and describe how you want to lay out your cells. However, thanks to Apple, it provides us with a premade layout called UICollectionViewFlowLayout
, which flow the layout by placing the cells one after the other based on their sizes and the spacing between them.
How to do it...
Create a new Xcode project with our lovely template Single View template and...