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