用 xib 生成 UICollectionViewSection 頭尾視圖
首先注冊(cè)一個(gè) UICollectionReusableView 類 ps:不注冊(cè)會(huì)crash
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
記住在XIB中 設(shè)置高度 ?以及開(kāi)啟頭尾視圖設(shè)置
再這個(gè)方法里生成頭視圖
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
判斷為頭視圖 或 尾視圖?
UICollectionElementKindSectionFooter?
UICollectionElementKindSectionHeader
if (kind == UICollectionElementKindSectionHeader)
{?
從隊(duì)列取頭視圖
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
reusableview = headerView;
}
reusable view 其實(shí)就是一個(gè)view?
reusableview.backgroundColor = [UIColor redColor];
return reusableview;
}