Today’s topic is UICollectionView using iOS9 Swift 2.1. We will learn how to use collection view the best example is in build photo app of iPhone. The UICollectionView class manages an ordered collection of data items, we can presents them using customisable layouts. UICollectionViews provide the same function as UITableViews except that a collection view is able to support more than just single-column layouts. Collection views support customisable layouts that can be used to implement multi-column grids, tiled layouts, circular layouts, and many more. We can even change the layout of a collection view dynamically.
So lets start with new project Name it to CollectionDemo.
Go to Main.storyboard drag and drop a UICollectionView to controller. In the “Size Inspector” you can resize the cell according to your need like here i created a cell of 150*150.
Next, select the Collection View Cell and set the identifier as “cell” in the Attribute Inspector.
Create an outlet and connect the delegates and datasource also import them into your ViewController.Swift class.
In Project Navigator, right-click and select “New File”. Create a new class that is a subclass of UICollectionViewCell and name it as “CollectionCell”. Select the cell and change its class to the “CollectionCell”, now drag drop a UILabel make its outlet on the custom cell class.
Lets do some coding for our UICollectionView using iOS9 Swift 2.1