UICollectionViewCell

To render something more than solid color rectangles, we need a custom cell view that will be used to display the data. With that in mind, we have to create a custom cell class which inherits from UICollectionViewCell. Because we will construct those cells with code (not using a storyboard layout), then we have to implement a specific constructor. If we have to use a storyboard, then we should implement the  init(coder:NSCoder) method. It's called once the storyboard is rendered on the screen.

Here is how we can start:

/** * Custom UICollectionViewCell which has a label on top. */class AnimalCollectionViewCell :UICollectionViewCell {    private var _label: UILabel     override init(frame: CGRect) { let fr = CGRect(x: 0, y: ...

Get Learn Swift by Building Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.