I have an array of UIButtons
that I would like to add to a UICollectionViewController
header.
Doing it via Interface Builder is easy, but I can't seem to find any resources for doing this in code.
Any ideas?
I have an array of UIButtons
that I would like to add to a UICollectionViewController
header.
Doing it via Interface Builder is easy, but I can't seem to find any resources for doing this in code.
Any ideas?
Implement the method -collectionView:viewForSupplementaryElementOfKind:atIndexPath:
method in the UICollectionViewDataSource protocol.
That method returns a UICollectionReusableView
, which is really just a view. As the previous poster said, simply create that an object of that type in the method, and use it as a normal UIView, adding buttons as subviews.
If you have a header in a XIB/storyboard that you want to add buttons to, just dequeue the correct view from the UICollectionView with a reuseIdentifer, then add them as subviews to that dequeued UICollectionReusableView.