UICollectionView is widely used in iOS apps. The most common example is the iOS photo app, which has a stylish way to display all photos in grid view or stack view. The collection view provide a simple way to let us build complicated layout by customising its cell view. Different from table view, collection view will show its cell views in grid layout. Each cell view can have different width and height. Therefore, it gives us more room to make special layout by UICollectionView.
Recently, I am going to create a file manager which will look very similar with iBooks, but will show cover and title altogether with different size. In the future, we can simply use this component in many apps, such as mp3 album app, file download manager app, or comic books app.
Start a Simple App with Collection View
Similar with UITableView and UITableViewCell, the collection view is also made up of UICollectionView and UICollectionViewCell. Additional, we can also customize the layout by setting collectionViewLayout. To build up a grid style view with UICollectionView, we can implement following delegates:
- UICollectionViewDelegate: the delegate set up the collection view.
- UICollectionViewDataSource: the delegate provide the data source for collection view.
- UICollectionViewDelegateFlowLayout (optional): UICollectionView provide us a flow layout. When we use the default layout, we can use this delegate to configure the layout such as size of items and the spacing between items. We can also set collectionViewLayout as our customized layout.
Read more