1.初始化后注册
[_collectionView registerNib:[UINib nibWithNibName:@"HTCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionViewHeader"];
2.实现接口
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section {
if (section == 0) {
return CGSizeMake(self.view.frame.size.width, appFrameHeight / 4);
}
else {
return CGSizeMake(0, 0);
}
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:@"UICollectionViewHeader"
forIndexPath:indexPath];
headView.backgroundColor = [UIColor redColor];
return headView;
}