ios uicollectionview 添加headview 效果实现


参考资料: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;
    
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM