UITableView

UICollectionView

  //UICollectionViewLayout

//UICollectionViewLayout决定了UICollectionView如何显示在界面上,Apple提供了一个最简单的默认layout对象:UICollectionViewFlowLayout。

//Flow Layout是一个Cells的线性布局方案,并具有页面和页脚。其可定制的内容如下:

//itemSize属性

//设定全局的Cell尺寸,如果想要单独定义某个Cell的尺寸,可以使用下面方法:

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

//minimumLineSpacing属性

//设定全局的行间距,如果想要设定指定区内Cell的最小行距,可以使用下面方法:

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;

//minimumInteritemSpacing属性

//设定全局的Cell间距,如果想要设定指定区内Cell的最小间距,可以使用下面方法:

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

//scrollDirection属性

//设定滚动方向,有UICollectionViewScrollDirectionVertical和UICollectionViewScrollDirectionHorizontal两个值。

//headerReferenceSize属性与footerReferenceSize属性

//设定页眉和页脚的全局尺寸,需要注意的是,根据滚动方向不同,header和footer的width和height中只有一个会起作用。如果要单独设置指定区内的页面和页脚尺寸,可以使用下面方法:

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

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;

//sectionInset属性

//设定全局的区内边距,如果想要设定指定区的内边距,可以使用下面方法:

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

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//UICollectionViewDataSource

//返回collection view里区(section)的个数,如果没有实现该方法,将默认返回1:

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

//返回指定区(section)包含的数据源条目数(number of items),该方法必须实现:

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

//返回某个indexPath对应的cell,该方法必须实现:

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

{

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

if(indexPath.section==0)

{

cell.backgroundColor = [UIColor redColor];

}

else if(indexPath.section==1)

{

cell.backgroundColor = [UIColor greenColor];

}

return cell;

}

//UICollectionViewCell结构上相对比较简单,由下至上:

//

//首先是cell本身作为容器view

//然后是一个大小自动适应整个cell的backgroundView,用作cell平时的背景

//再其次是selectedBackgroundView,是cell被选中时的背景

//最后是一个contentView,自定义内容应被加在这个view上

//为collection view添加一个补充视图(页眉或页脚)

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

//设定页眉的尺寸

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

//设定页脚的尺寸

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

//添加页眉和页脚以前需要注册类和标识:

- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier

//设定指定区内Cell的最小行距,也可以直接设置UICollectionViewFlowLayout的minimumLineSpacing属性

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

//设定指定区内Cell的最小间距,也可以直接设置UICollectionViewFlowLayout的minimumInteritemSpacing属性

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

//UICollectionViewDelegate

//当指定indexPath处的item被选择时触发

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

//P.s. 当你删除或添加元素时,一定要更新numberOfItemsInSection的返回情况。

//当指定indexPath处的item被取消选择时触发,仅在允许多选时被调用

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath

//下面是三个和高亮有关的方法:

//事件的处理顺序如下:

//

//手指按下

//shouldHighlightItemAtIndexPath (如果返回YES则向下执行,否则执行到这里为止)

//didHighlightItemAtIndexPath (高亮)

//手指松开

//didUnhighlightItemAtIndexPath (取消高亮)

//shouldSelectItemAtIndexPath (如果返回YES则向下执行,否则执行到这里为止)

//didSelectItemAtIndexPath (执行选择事件)

//如果只是简单实现点击后cell改变显示状态,只需要在cellForItemAtIndexPath方法里返回cell时,指定cell的selectedBackgroundView

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath

转载于:https://www.cnblogs.com/crazygeek/p/5537898.html

复习知识点:UITableView和UICollectionView的常用属性相关推荐

  1. CSS知识点——盒子布局及一些常用属性

    CSS知识点--盒子布局及一些常用属性 - 盒子布局 先上一张图,方便理解后面的布局内容 盒子布局的主体通常为 div 标记(分区标签),这里不得不提一下 span 标签,它也是一个区域标签,但是区别 ...

  2. 计算机vb2级知识点,2020年全国计算机二级VB复习知识点:VB编码规则

    2020年全国计算机二级VB复习知识点:VB编码规则,[摘要]备考2020年全国计算机二级考试的小伙伴们,复习的都怎么样了呢?环球网校小编整理了2020年全国计算机二级VB复习知识点供大家参考复习,小 ...

  3. css知识点笔记-常用属性

    css知识点范围:常用属性 删除线:text-decoration : line-through 下划线:text-decoration : underline 斜体:font-style : ita ...

  4. 计算机vb知识点,2020年全国计算机二级VB复习知识点:常用内部函数

    [摘要] 小编整理了2020年全国计算机二级VB复习知识点:常用内部函数的相关内容,下面一起来看看2020年全国计算机二级VB复习知识点:常用内部函数的具体内容吧,希望能够帮助到大家! 2020年全国 ...

  5. 前端常用属性知识点--文档

    清除浮动带来的影响--.clearfix .clearfix{ *zoom:1; } .clearfix::after{content: "";display: block;cle ...

  6. 山东大学软件工程期末复习知识点总结

    山大软院软件工程期末复习知识点总结,根据任课老师所给提纲及课件等资料进行整理. 考试范围全覆盖. 文档电子版下载地址 目录 第一章 1.1软件工程(SE)的定义.目的.方法.作用: //1.2开发模式 ...

  7. 计算机会考程序设计循环语句知识点,算法与程序设计会考复习知识点

    <算法与程序设计会考复习知识点>由会员分享,可在线阅读,更多相关<算法与程序设计会考复习知识点(19页珍藏版)>请在人人文库网上搜索. 1.信息技术会考复习(算法与程序设计)1 ...

  8. 2020计算机取消vb,2020年全国计算机二级VB复习知识点:创建VB应用程序的一

    [摘要] 即将参加全国计算机等级考试的考生们,考试即将到来,大家的备考工作进行得如何了?考必过为大家精心整理了2020年全国计算机二级VB复习知识点:创建VB应用程序的一,希望能够助力全国计算机等级考 ...

  9. python期末复习知识点总结

    期末复习知识点总结 第一章 1.6 Python编程规范与代码优化建议 1.7 模块 模块的导入方式 补:Python编程规范与代码优化建议 注释 以符号#开始,表示本行#之后的内容为注释. #eg1 ...

最新文章

  1. STL map 简介
  2. 基于YOLOv5的智慧工地安全帽检测(1)
  3. 创建图像 php,详解php创建图像具体步骤
  4. 手动启动“远程过程调用”服务时,出现错误信息1058
  5. [YTU]_2576( 虚函数练习:动物2)
  6. 科大星云诗社动态20210501
  7. postman断言之常用函数
  8. python- 基础 range方法的使用
  9. Ubuntu 每日技巧- 自动备份Ubuntu 14.04到Box云存储上
  10. meta标签的常见用法
  11. UIProgressView-初识IOS
  12. Spark分布式集群的搭建和运行
  13. @kafkalistener中id的作用_SSM框架(十一):Spring框架中的IoC(1)
  14. android出现错误,在做一个安卓的一个登陆操作的时候,出现错误
  15. uinty粒子系统子物体变大_新Unity 最新粒子系统如何用代码改变参数
  16. LabVIEW升级图像识别功能
  17. 5G时代的一个杀手级应用,可能是“云上电脑”?
  18. Win10安装了Office右键没有新建Word,excel,PPT等选项解决方法
  19. java中获取当月1号零时零分的时间
  20. 高中计算机教师具备能力,新时代信息技术教师应具备哪些能力和素养

热门文章

  1. 《架构之美》学习随笔:好的架构
  2. Spring Android 1.0.0.M3 发布
  3. 《JavaScript高级程序设计》笔记总结
  4. [pytorch、学习] - 9.2 微调
  5. koa --- 跨域,解析POST参数、路由配置
  6. java基础集合类——LinkedList 源码略读
  7. Linux 操作命令 more
  8. Hadoop Mapreduce分区、分组、二次排序过程详解
  9. QtCreator添加图片资源
  10. Windows on Device 项目实践 4 - 智能风扇制作