Assigning a custom layout to your collection view

The final step to using your custom layout is telling your collection view to use your layout. You have already seen that you can assign a custom class to the layout for a collection view in Interface Builder. However, this only works when your layout inherits from UICollectionViewFlowLayout, which your layout does not inherit from. Luckily, you can also set your collection view's layout in code. Update your viewDidLoad method in ViewController.swift by adding the following line to it:

collectionView.collectionViewLayout = ContactsCollectionViewLayout()

This line sets your new layout as the current layout. You can now remove the UICollectionViewDelegateFlowLayout extension from ViewController.swift as it is not needed anymore.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset