2

I am using a UICollectionViewController and would like to set a headerView (not a section header view) at the top of the collectionView, similar to how you can set the tableViewHeader for a UITableView.

So far, I have found nothing about this.

Is it not possible?

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412

1 Answers1

-2

UICollectionView has a SupplementaryView.

You can register a view with

- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;

and use with :

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

If you want a fixed header like UITableViewStylePain, check the below link.

How to make Supplementary View float in UICollectionView as Section Headers do in UITableView plain style

Community
  • 1
  • 1
Ryan
  • 4,799
  • 1
  • 29
  • 56
  • But you seem to be talking about section headers. I just want one header at the top of the `UICollectionView` just like `UITableView` provides with `tableViewHeaderView`. – Nic Hubbard Jan 09 '15 at 16:34
  • 1
    Subclassing `UICollectionViewLayout` must be the only answer. You can customize almost every thing with it. – Ryan Jan 11 '15 at 04:38