How to create custom cells for UICollectionView using Swift

Let’s continue our journey through the UICollectionView class. Creating cells for UICollectionView is really easy, moreover you can use the same approach for UITableView. Let’s take a look at how to do it using Swift.

You will learn how to create simple cells with text and images in them, how to handle taps, and at the end of the article I’ll talk about how to use a xib file to create a cell.

In this tutorial I presume that you’ve already finished my previous tutorial — How to create UICollectionView using Swift without storyboards, because here I’ll use our finished Xcode project. If you didn’t, then don’t worry, the only thing you need here is working UICollectionView. Continue reading “How to create custom cells for UICollectionView using Swift”

How to create UICollectionView using Swift without storyboards

There’s a lot of tutorials about how to create a UICollectionView using storyboards or just nib files. I don’t like Interface Builder and prefer to do everything in code. Most of the time it’s easier, it creates less bugs, so in this tutorial we will create UICollectionView programmatically.

UICollectionView is highly customizable class for presenting your content in almost any layout you want. If you want Apple to tell you basics about it, visit WWDC 2012 videos “Introducing Collection Views” and “Advanced Collection Views and Building Custom Layouts”. It implements in a similar way to UITableView — using UICollectionViewDataSource and UICollectionViewDelegate protocols. Let’s take a look at how to do it using Swift. Continue reading “How to create UICollectionView using Swift without storyboards”