Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Subclass UICollectionView?

I would like to customize the UICollectionView, but all the tutorials on the web and in books use UICollectionViewController which I do not want to use. I'm combining different kinds of UICollectionViews in the same UIViewController, so I don't want to limit myself by subclassing UICollectionViewController, which doesn't allow me to place several UICollectionViews in the same viewController along with other objects and labels.

How do I subclass UICollectionView? Specifically, what kinds of methods need to be overwritten? How do I layout what goes into it (i.e. where to put a text label, image, etc.)? I'm familiar with the data source / delegate protocols, but not quite sure how to customize the cell's look, placement of sub items within the cell, what classes need to be overwritten/sub classed, etc.

A list of things I need to do would be much appreciated!

Thanks!

like image 937
Erika Electra Avatar asked Aug 27 '26 07:08

Erika Electra


1 Answers

I believe that you don't need to sub-class UICollectionView but you need to sub-class UICollectionViewFlowLayout.

UICollectionViewFlowLayout is the object which manages the display of the collection view items and it is highly customizable.

I suggest you follow WWDC 2012:Advanced Collection Views and Building Custom Layouts

The best tutorial which worked for me was by Apple called Using the Flow Layout.

like image 107
Raz Avatar answered Aug 29 '26 21:08

Raz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!