zoukankan      html  css  js  c++  java
  • UICollectionview的头视图和尾视图

    UITableView有头视图和尾视图,那么UICollectionView有没有头视图和尾视图呢?

    答案是有的.

    1.新建一个类,必须继承自 UICollectionReusableView.

    2.需要实现UIcollectionViewDataSource中的方法:viewForSupplementaryElementOfKind;

     1 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
     2 
     3     UICollectionReusableView *reusableView = nil;
     4 
     5     if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
     6 
     7         HLTopicItemHeader * header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kTopicHeaderIdentifier forIndexPath:indexPath];
     8 
     9         //有缓存了
    10         [header.imgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kDataServer2,_topic_img_url]] placeholderImage:[UIImage imageNamed:@"AppIcon60x60@3x"]];
    11 
    12         header.title.text = _topic_title;
    13         reusableView = header;
    14     }
    15 
    16     return reusableView;
    17 }

    今天才知道UICollectionView原来还有头视图和尾视图呀...嘿嘿!!!

  • 相关阅读:
    swift学习-----字典
    Swift学习----数组
    Swift学习-----循环
    Swift学习-----可选类型
    Swift学习-----分支
    Swift学习------常量与变量
    autorelease,autoreleasepool基本使用
    SDWebImage缓存图片的机制(转)
    新闻网站项目django--分类页
    新闻网站项目django--首页
  • 原文地址:https://www.cnblogs.com/pengsi/p/5336593.html
Copyright © 2011-2022 走看看