在CollectionView添加头部视图
来源:互联网 发布:淘宝规蜜pc端入口 编辑:程序博客网 时间:2024/05/16 16:17
关键代码如下:
static NSString *headerViewIdentifier = @"hederview";-(void)addCollectionView{ _layout = [[UICollectionViewFlowLayout alloc]init]; _layout.minimumLineSpacing=20; //设置每一行的间距 _layout.itemSize=CGSizeMake((kDeviceWidth - 38) / 2, (kDeviceWidth - 38) / 2 + 50 ); //设置每个单元格的大小 _layout.sectionInset=UIEdgeInsetsMake(20, 14, 20, 14);//设置间隔 _layout.headerReferenceSize=CGSizeMake(self.view.frame.size.width,60); //设置collectionView头视图的大小 _collectionView =[[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:_layout]; _collectionView.delegate=self; _collectionView.dataSource=self; self.defaultView.hidden=YES; _collectionView.frame=self.view.bounds; _collectionView.backgroundView=self.defaultView; _collectionView.backgroundColor=kColorTextGray_246; //注册cell单元格 [_collectionView registerClass:[DiscoveryCollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; //注册头视图 [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerViewIdentifier]; [self.view addSubview:_collectionView];}
// 返回头视图- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ //如果是头视图 if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerViewIdentifier forIndexPath:indexPath]; //头视图添加view [header addSubview:self.scrollView]; [header addSubview:self.pageControl]; return header; } return nil;}
0 0
- 在CollectionView添加头部视图
- collectionView添加头部view
- CollectionView添加头部
- collectionView怎么添加头视图
- UIWebView添加头部视图
- PullToRefreshBase添加头部视图
- CollectionView视图
- collectionview头部悬浮
- CollctionView添加头部视图,不是sectionHeader
- CollectionView瀑布流添加头视图,自定义Cell计算高度
- iOS--集合视图CollectionView
- XZ_iOS之在webView的头部添加一个头视图并随着webView滚动,webView底部的黑色部分去掉
- StikkyHeader——为滚动视图添加粘性头部
- SWIFT写的web view添加头部与尾部视图
- RecyclerView封装Adapter之添加头部和底部视图
- 在windows添加视图
- CollectionView 添加/删除动画
- 使用CSStickyHeaderFlowLayout实现头部固定的CollectionView
- CSS引用方式
- IOS开发心得汇总
- C#+vs2013+windows10配置emgu技巧
- ios 之 autoresizing小解
- Smobiler实现类似朋友圈功能—MicroBlog控件(开发日志十七)
- 在CollectionView添加头部视图
- 如何进行shell脚本正确性测试
- socket编程——一个简单的例子
- OpenCV Haar AdaBoost源码改进(比EMCV快6倍)
- RabbitMQ消息队列(五):Routing 消息路由
- 5.1.2 SMTPD_CMD结构体:smtp协议命令表示
- sectionheadView 跟随UItabview滚动 去掉UItableview headerview黏性
- android自定义view-打造圆形ImageView(三)
- intent://platformapi/startapp?--Webview内跳转到支付宝网页