Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView Header and Footer View

I'm using a UICollectionView and need a global header and footer together with section headers. Both global header and footer are supposed to scroll with the rest of the content. Basically they should work exactly like UITableView's tableHeaderView and tableFooterView properties.

diagram

From what I understand supplementary views are either above or below a specific section and decoration views are functionless. My global header and footer are supposed to have interactive elements.

I'm really pulling my hair out after trying for a couple of hours. I found a couple of nasty ways such as hacking around with contentInsets and adding subview to the collectionview. What I'm really looking for is a clean way to do this.

I'm looking forward to any advice!

like image 379
paul Avatar asked Jul 16 '13 15:07

paul


People also ask

How do I add a header in collection view?

There are no section headers in the UICollectionView. So for your first task, you'll add a new section header using the search text as the section title. To display this section header, you'll use UICollectionReusableView .

What is collection reusable view?

Overview. Reusable views are so named because the collection view places them on a reuse queue rather than deleting them when they're scrolled out of the visible bounds. Such a view can then be retrieved and repurposed for a different set of content.


1 Answers

You'll have to create your own custom collection view layout and datasource. The datasource will return global headers and global footers, and section headers and footers, and your custom collection view layout will have to position them accordingly.

THIS IS NOT A VERY SIMPLE PROCESS.

In the WWDC talk Advanced User Interfaces with Collection Views they describe their approach with sample code on how they created a global header. You can use their sample code and then add a global footer section to that.

From Apple:

Advanced User Interfaces with Collection Views

Demonstrates code factoring, swipe to edit, drag reordering, and a sophisticated custom collection view layout.

like image 66
kurryt Avatar answered Sep 23 '22 03:09

kurryt