Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a UICollectionViewLayout subclass in a storyboard

I'm using a storyboard for my project and I want to have a scene that's a UICollectionViewController sub class, who's UICollectionView uses a UICollectionViewLayout subclass.

I've set this up in a storyboard, and I'm trying to change the "Custom Class" of the collection view's layout instance.

Here's a screen grab of the layout object that I have selected in the storyboard:

Storyboard object tree with <code>UICollectionViewLayout</code> selected

Here's a screen grab of storyboard's "Identity" inspector pane showing the "Custom Class" field that I am changing (it's at the top):

Storyboard Identity inspector showing "Custom Class"

When I try to change the "Custom Class", I can change type stuff in, but after saving, the it reverts back to being the default UICollectionViewFlowLayout. If I run the project, the default UICollectionViewFlowLayout gets used even though it's not the custom class I have set.

How can I set a custom layout class, please?

like image 364
Benjohn Avatar asked Jan 02 '14 11:01

Benjohn


1 Answers

The approach you've used would usually let you change the class of an instance in a storyboard. However, for a UICollectionView, you need to do something slightly different.

Instead of selecting the UICollectionViewLayout instance itself and adjusting its custom class parameter, select the UICollectionView instance, as show in this screen grab:

Storyboard object tree with <code>UICollectionView</code> instance selected

Now, in the storyboard inspector, select the "Attributes" inspector pane for the UICollectionView instance. You'll see something like this:

Storyboard Attributes inspector with "Flow" selected

You need to change the "Layout" field combo box so that instead of "Flow" being selected, "Custom" is selected. A text field will then be appear to set your UICollectionViewLayout custom subclass, like this:

Storyboard Attributes inspector with "Custom" selected

like image 100
Benjohn Avatar answered Nov 02 '22 10:11

Benjohn