參考資料:http://www.myexception.cn/mobile/1856317.html //uicollectionview 純代碼格局, 添加頭部視圖
uicollectionview的基本使用這里就不寫了 百度一大堆
自己寫一個UIView 繼承 UICollectionReusableView
@interface myHeadView : UICollectionReusableView
{
UILabel *TitleLable;
}
-(void)setTextTitle;
@end
添加headview 實際上是 使用了uicollectionview的 SectionHeader來實現類似於 tableview 的 tableheaderview效果
[_myConllectionView registerClass:[myHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeadView"];
然后實現以下的協議
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
NSLog(@"kind = %@", kind);
if (kind == UICollectionElementKindSectionHeader){
myHeadView *headerV = (myHeadView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeadView" forIndexPath:indexPath];
[headerV setTextTitle];
reusableview = headerV;
}
return reusableview;
}
