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原来还有头视图和尾视图呀...嘿嘿!!!

原文地址:https://www.cnblogs.com/pengsi/p/5336593.html