复习知识点:UITableView和UICollectionView的常用属性

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属性

    //设定滚动方向,有UICollectionViewScrollDirectionVerticalUICollectionViewScrollDirectionHorizontal两个值。

    //headerReferenceSize属性与footerReferenceSize属性

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

    - (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

    //然后是一个大小自动适应整个cellbackgroundView,用作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的最小行距,也可以直接设置UICollectionViewFlowLayoutminimumLineSpacing属性

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

    

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

    - (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时,指定cellselectedBackgroundView

    - (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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/271715.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ASP.NET+MVC+使用+Log4net+记录日志笔记

前言:记录系统中的日志,是一个好的项目产品必备的一个环节。每一个产品最终的目的都是要交予客户使用,因为程序员代码的开发水平参差不齐,Bug就成为了项目运维成本最大的因素之一。如何降低项目运维的成本呢,最重要的是…

git分支feature和hotfix分支

master: 主分支,主要用来版本发布。develop:日常开发分支,该分支正常保存了开发的最新代码。feature:具体的功能开发分支,只与 develop 分支交互。release:release 分支可以认为是 master 分支的未测试版。…

linux查看镜像的详细信息,docker inspect命令查看镜像详细信息

# docker inspect ubuntu:18.04 // 查看镜像的详细信息[{"Id": "sha256:d131e0fa2585a7efbfb187f70d648aa50e251d9d3b7031edf4730ca6154e221e","RepoTags": ["ubuntu:18.04"],"RepoDigests": ["ubuntusha256:d26d529da…

Golang使用pkg-config自动获取头文件和链接库的方法

为了能够重用已有的C语言库,我们在使用Golang开发项目或系统的时候难免会遇到Go和C语言混合编程,这时很多人都会选择使用cgo。 话说cgo这个东西可算得上是让人又爱又恨,好处在于它可以让你快速重用已有的C语言库,无需再用Golang重…

数据库:SQLServer中with as 用法笔记

一、with as 概念介绍with as 也叫做子查询部分(subquery factoring),可以定义一个SQL段落,该SQL段落可以被整个SQL语句所用到类似于临时表的作用。with as 可以提高你的SQL语句的可读性,也有可以用在在UNION ALL的不同…

单词

Screenshot 屏幕截图,截图 Dashboard n. 仪表盘 subscribe vt. 签署;赞成;捐助 vi. 订阅;捐款;认购;赞成;签署 performance n. 性能;绩效;表演;执行 optimization …

数据库优化:SqlServer的with(nolock)关键字的用法介绍

一、with(nolock)的介绍数据库写查询语句的时候,为了提升查询性能,往往会在查询的表后面加一个nolock,或者是with(nolock),其目的就是查询的时候是不锁定表,从而提高查询速度的目的。但如果同一时间有多个用户访问同一资源的时候,如果并发用户对该资源做了修改。则会…

对layoutInflater的理解

参考该博客:http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html LayoutInflater是一个抽象类,通过调用其实例方法inflate(),将res/layout下的xml布局文件进行实例化,不同于findvirebyid()是找布局文件下的控件进行实例…

linux /root /etc,Linux知识:/root/.bashrc与/etc/profile的异同

要搞清bashrc与profile的区别,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell。交互式模式就是shell等待你的输入,并且执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。这种模式也是…

java多线程售票例子

代码如下: public class Ticket1 implements Runnable {private int tickets 100;Overridepublic void run() {while (tickets > 0) {synchronized (Ticket.class) {if (tickets > 0) {tickets--;System.out.println(Thread.currentThread().getName() "正在卖票&…

推荐一款免费国产远程办公神器ToDesk,TeamViewer完美替代品

对于从事IT行业的人员来说,远程软件基本上是必备的软件。之前使用用TeamViewer远程办公软件,它的稳定性、延迟低、功能齐全很受广大开发者的欢迎。唯一美中不足的是它是一款商业软件。费用比较高。到现在基本上所有破解工具都无效了。所以不得不放弃这款…

[iOS] photoKit获取所有照片

代码: - (NSMutableArray *)getAllPhoto{NSMutableArray *arr [NSMutableArray array];// 所有智能相册PHFetchResult *smartAlbums [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular optio…

用python写linux中的ls,Python实现Linux环境下的ls命令

在Linux下使用ls命令结合正则表达式,能够高效地进行文件搜索,并通过参数操作文件,于是就想用Python实现这个功能以便在Windows上使用import osimport reimport syspath os.getcwd()substr raw_input(The sub-string of the file (Support f…

苹果台式电脑怎么开机_龙华苹果电脑回收公司,台式电脑回收公司电话

龙华苹果电脑回收公司,台式电脑回收公司电话oDYIHx 通常液晶显示器有VGA和DVI两种种接口,其中VGA接口在长时间显示后悔出现画面模糊情况,需要校正才能恢复,然而DVi接口传输就比较稳定,它属于全数字无损传输信号,在长…

AtomicInteger使用非阻塞算法,实现并发控制多线程实现售票

代码如下: public class TicketDemo implements Runnable {private static volatile AtomicInteger ticketSum new AtomicInteger(20);private static int finalTotal 0;Overridepublic void run() {int count;while ((count ticketSum.decrementAndGet()) > 0) {System.…

数据库:SQLServer 实现行转列、列转行用法笔记

在许多的互联网项目当中,报表开发是整个项目当中很重要的一个功能模块。其中会有一些比较复杂的报表统计需要行转列或者列转行的需求。今天给大家简单介绍一下在SQLServer当中如何使用PIVOT、UNPIVOT内置函数实现数据报表的行转列、列转行。有需要的朋友可以一起学习…

硬件知识:串口通讯的起始、数据、停止位是怎么分配的?

串口是串行接口(serial port)的简称,也称为串行通信接口或COM接口。串口通信是指采用串行通信协议(serial communication)在一条信号线上将数据一个比特一个比特地逐位进行传输的通信模式。串口按电气标准及协议来划分…

ES5 getter setter

最近在学习vuejs,了解到内部实现使用到了es5的Getters和Setters。之前看高程的时候,没有重视这块,今天查看一下文档,了解了他们的作用,再次记录一下,可供以后查看和共享。 定义Getters和Setters&#xff1a…

python 调用bat失败_要想顺利通过Python面试,你最起码需要达到白银段位!

近几年 Python 非常热门,在学术界和产业界的使用率显著提高。目前学习Python的人数日益增多,Python在近3年的编程语言受欢迎度中一直处于榜首。今天我们就来讲讲在产业界,需要具备哪些能力才能获得一个满意的 Python 相关岗位 Offer。Python基…

多线程售票demo,用ReentrantLock实现

代码: public class TicketReentLockDemo implements Runnable {private int ticketTotal 100;private Lock lock new ReentrantLock();Overridepublic void run() {while (ticketTotal > 0) {try {lock.lock();if (ticketTotal > 0) {try {TimeUnit.MILLISECONDS.sle…