I'm trying to create a sticky supplementary header, which stays on top all the time and won't response to scrolling events. The solutions I found so far still react on bounch scrolling and are fixed using a custom flowLayout, which will probably be the fix for mine issue as well.
The reason I want it this way is that the header is used on other places and should be reusable. I'm hoping this could be solved this way and I don't have to create a separated view.
As I'm doing this in Swift, it would be great to have an example in Swift.
Cleaner Swift 2.3 tested version of Irina's answer
Simplest solution for iOS 9 + as it doesn't need of writing subclass of UICollectionViewFlowLayout.
In viewDidLoad of viewController with collectionView use following code:
It is hinted by @Antoine also.
I fixed my crash by testing for testing for empty sections as suggested in this gist. I also added a couple of
if let
s for extra Swift style points ;-). This now works for me:Swift 3 version trying to avoid !'s where it made sense.
works for me with swift 2.0
i use this in my project. Hope it helps.
of course. you can return whatever size you want.