UICollectionView显示HeaderView FooterView 不如UITableView那么容易,常用会有两种做法:

1.Xib或者Storyboard 在属性一栏中设置一下:



如图所示,

2.代码设计Section的header和Footer:

好多都在找UICollectionView是否有这么个属性,比如上图说到Accessories什么的,其实不然。大家首先要搞明白意见事情,header和footer是追加视图,属于layout中的所以要代码设置section要在UICollectionViewFlowLayout:

- (UICollectionViewFlowLayout *) flowLayout{
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.。。。。。。//各属性设置
flowLayout.headerReferenceSize = CGSizeMake(320.0f, 50.0f); //设置headerView大小
flowLayout.footerReferenceSize = CGSizeMake(320.0f, 50.0f); // 设置footerView大小
return flowLayout;
}
如果你用的是Xib或者Storyboard,不想在上图属性设置,想用代码:
- (void)viewDidLoad
{
[super viewDidLoad]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.headerReferenceSize = CGSizeMake(320.0f, 50.0f); //设置headerView大小
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"]; // 一定要设置
[self.collectionView setCollectionViewLayout:layout];
//(这部分说明可以参见xib设置sectionview)
} - (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WINSIZE.width, WINSIZE.width*7/15)];
[imageView sd_setImageWithURL:[NSURL URLWithString:[UMOnlineConfig getConfigParams:@"GuizeImageUrl"]] placeholderImage:kDefaultImage192_124];
[headerView addSubview:imageView];
return headerView;
}

运行结果:

最新文章

  1. Xcode自动注释插件
  2. ACdream 1115 Salmon And Cat (找规律&&打表)
  3. android Animation 动画效果介绍
  4. 运行edX Devstack
  5. crossfire 346# B
  6. 自学Python的点滴
  7. HTML5 Placeholder实现input背景文字提示效果
  8. javascript面向对象2
  9. linux中服务器定时程序设定
  10. NOIP2016提高组初赛(C++语言)试题 个人的胡乱分析 Part 2.
  11. 关于PL/SQL Developer与Oracle客户端
  12. 机器学习中数据清洗&预处理
  13. 基于OpenSSL的HTTPS通信C++实现
  14. Linux安装Gitlab,附iSCSI分区挂载说明
  15. yum安装命令:遇到的问题报错如下: File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: 通过看报错可以了解到是使用了python2的语法,所以了解到当前yum使用的Python2,因为我单独安装了python3,且python3设置为默认版本了,所以导致语法问题 解决方法: 使用python2.6 yum install
  16. eclipse里面找不到databaseexplorer
  17. iOS for MachineLearning
  18. markdown的学习记录
  19. Redis分布式锁的实现
  20. scrapyd远程连接配置

热门文章

  1. linux环境下安装jmeter,启动执行脚本
  2. 从零开始学spring cloud(五) -------- 将服务注册到Eureka上
  3. R语言读取XML数据
  4. easyui的datagrid改变整行颜色
  5. 2018-2019-2 20165315 《网络对抗技术》Exp3 免杀原理与实践
  6. IDEA开发环境中快捷键与系统 QQ等冲突的解决办法
  7. Codeforces 1083C Max Mex
  8. 记一次Struts2 内核问题分析解决
  9. JSP 页面跳转中的参数传递
  10. 老赵点滴地址:http://blog.zhaojie.me/2009/05/a-simple-actor-model-implementation.html