应用场景:

UICollectionView 横滑和竖滑只支持一种,要是想兼用 必须套一下两个UICollectionView一起使用

基本使用

1:首先需要先添加UICollectionView的代理:UICollectionViewDelegate   UICollectionViewDataSource  UICollectionViewDelegateFlowLayout

2:UICollectionView 注册cell 注册header都在同一个地方

代码:

在cell中 写标识

static NSString *const Capital_HeaderCollectionViewCellId = @"Capital_HeaderCollectionViewCellId";

header大小

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {

return :CGSizeZero;

}

header视图

- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

UICollectionReusableView *reusableview = nil;

if (kind == UICollectionElementKindSectionHeader){

Capital_HeaderCollectionViewCell *myHeaderView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:Capital_HeaderCollectionViewCellId forIndexPath:indexPath];

if (indexPath.section == 1) {

myHeaderView.title = @"免费体验";

}else if (indexPath.section == 2){

myHeaderView.title = @"资本价淘金股";

}

//在这里进行headerView的操作

reusableview = myHeaderView;

}

return reusableview;

}

section数量

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

row数量

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

每个cell大小

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

return CGSizeZero;

}

每个cell之间的距离 上左下右

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

return UIEdgeInsetsMake(0, 0, 0, 0);

}

每个itme 之间距离

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

复用cell

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

iOS UICollectionView 使用相关推荐

  1. iOS UICollectionView示例教程

    In this tutorial we'll look into iOS UICollectionView component and develop a basic application out ...

  2. iOS UICollectionView的实现

    ios的UICollectionView并不能在iOS6之前的版本中使用,为了兼容之前的版本需要自定义UICollectionView.写完之后发现人家已经有开源了,下过来看了看发现我是用UIScro ...

  3. iOS UICollectionView 高级用法(长按cell移动重新排列)

    iOS9 之后 前言: 看完你可以学到哪些呢? 就是文章标题那么多, 只有那么多. . 手残效果图没弄好. @property (nonatomic, strong) UICollectionView ...

  4. iOS UICollectionView实现瀑布流(3)

    前面两篇Blog简单的介绍了UICollection的基本使用并实现了类似Android的Gallery效果,这篇文章使用UICollection来实现瀑布流效果,代码主要是在极客学院Carol老师的 ...

  5. IOS -- UICollectionView里面的cell点击,点击一个cell改变其他cell的状态

    view.m - (void)initWithCreatorCollectView {//模拟数据 [self imitateData];float width = ([UIScreen mainSc ...

  6. 【Swift】iOS UICollectionView 计算 Cell 大小的陷阱

    前言 API 不熟悉导致的问题,想当然的去理解果然会出问题,这里记录一下 UICollectionView 使用问题. 声明  欢迎转载,但请保留文章原始出处:)  博客园:http://www.cn ...

  7. iOS UICollectionView的简单使用和常用代理方法

    UICollectionView相对于UITableView有更加自由的布局,做出的界面可变性更大最近开始接触使用UICollectionView,整理了一下常用的代理方法. 首先需要先添加UICol ...

  8. iOS UIcollectionview 数据量少时候bounces无效的解决方法

    uiCollectionView在数据量很少时候.不足以填满整个屏幕的时候bounces默认关闭. 解决方法 - (void)_edgeInsetsToFit { UIEdgeInsets edgeI ...

  9. iOS UICollectionView— reloadData后变空白,cellForItemAtIndexPath不执行

    最近项目在使用UICollectionView的时候,发现一个大坑,问题描述: 1.无法全部加载数据,contentSize是正确的,可以滑动 2.下拉刷新的时候,执行了reloadData,页面出现 ...

最新文章

  1. python yield 和 yield from用法总结
  2. Web前端经典面试试题(二)
  3. python初级数据分析师薪资_学会数据分析,薪资翻倍?!
  4. Hadoop大数据——mapreduce的join算法
  5. Nginx搭建部署Web服务器并与NFS结合搭建负载均衡服务器
  6. WebClient UI create a hidden form and submit
  7. Cloud for Customer元数据的加载
  8. ORACLE关于段的HEADER_BLOCK的一点浅析
  9. 适配器模式之对象适配器
  10. Netty工作笔记0005---NIO介绍说明
  11. jQuery学习(十二)—jQuery中对象的查找方法总结
  12. 春晚亲民,快手上行:探秘春晚红包的另一种打开方式
  13. 垃圾代码评析——关于《C程序设计伴侣》9.4——链表(一)
  14. go语言中函数与方法重要的区别:
  15. 在线职业教育高保真移动端Axure原型模板
  16. java生成zipf分布_数据存储中Zipf分布
  17. spyder5 加载完毕闪退
  18. 每日一诗词 —— 访戴天山道士不遇
  19. 我什么计算机作文600字,我是电脑迷作文600字
  20. 爱荷华大学计算机科学专业,爱荷华大学计算机科学本科爱荷华大学计算机科学本科.pdf...

热门文章

  1. 常见的内存泄漏原因及解决方法
  2. ”dpkg: 处理归档 /var/cache/apt/archives/XXXXXX(--unpack)时出错“的解决方法
  3. laravel中TokenMismatchException异常处理
  4. 什么是__pycache__?
  5. 从python中的列表中获取唯一值[重复]
  6. 获得插入行身份的最佳方法?
  7. JavaScript闭包如何工作?
  8. ASP.NET 页面之间传递值的几种方式
  9. PowerDesigner反向生成物理数据模型
  10. Rushcrm:客户关系管理适合的才是好的