UIScrollView,UICollectionView 和UITableView

三者之间的关系:UIScrollView是 UICollectionView 和 UITableView 的父类.

UIScrollView

一个可以滚动的视图控件,可以用来查看比屏幕大很多的视图内容.

常用属性:

contentOffset:当前显示的区域相对于frame顶点的区域

contentSize:屏幕能滚动到的最大区域(画布)

contentInset:scrollview的contentview的顶点相对于scrollview的位置

directionalLockEnabled:是否禁止在某一方向的滚动

bounces:是否有弹框效果

alwaysBounceVertical:是否在垂直方向有反弹效果

alwaysBounceHorizontal:是否在水平方向上有反弹效果

pagingEnabled:是否有分页效果

scrollEnabled:是否能滚动

showsHorizontalScrollIndicator:是否显示水平滚动条

showsVerticalScrollIndicator:是否显示垂直滚动条

scrollIndicatorInsets:滚动指示器从封闭滚动视图中被嵌入的距离

indicatorStyle:滚动控制器的风格

decelerationRate:用户离开屏幕后滚动的减速速率

indexDisplayMode://数据显示方式

tracking:用户是否触摸内容并初始化滚动

dragging:是否开始滚动

decelerating:手指在离开屏幕后,屏幕是否继续滚动

delaysContentTouches:滚动视图是否延迟处理触摸下压事件

canCancelContentTouches:触摸内容视图是否总是跟踪

minimumZoomScale:最小缩放比例

maximumZoomScale:最大缩放比例

zoomScale:缩放比例

bouncesZoom:规定滚动视图是否在缩放超出最大值和最小值动画时播放内容缩放动画

zooming:是否缩放

zoomBouncing:缩放超出缩放限制

scrollsToTop:是否滚动到顶部

panGestureRecognizer:当前用于滑动手势的手势识别器

pinchGestureRecognizer:当前用于扩张/收缩手势的手势识别器

directionalPressGestureRecognizer:按压手势移动方向

keyboardDismissMode:键盘消失方式

refreshControl:更新控制

常用方法

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;//设定当前显示的区域相对于frame顶点的区域

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;//滚动内容的指定区域以便使内容在屏幕中可见

- (void)flashScrollIndicators; //短暂地显示滚动指示器

- (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event inContentView:(UIView *)view;//(方法被滚动视图调用)以调整滚动视图处理滚动手势的方式

- (BOOL)touchesShouldCancelInContentView:(UIView *)view;//触摸是否可以取消

- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated ;//设置缩放比例

- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;//将内容视图缩放到指定的Rect中

UICollectionView

常用属性:

collectionViewLayout:布局

prefetchingEnabled:是否预加载

backgroundView:背景视图

allowsSelection:是否允许 item可以点击

allowsMultipleSelection:是否允许多选

indexPathsForSelectedItems:选中的 item

numberOfSections:显示多少 item

visibleCells:界面上显示的 cell

indexPathsForVisibleItems:当前可视界面上显示的 item 的 indexPath

remembersLastFocusedIndexPath:是否记住最后操作的 indexPath

常用方法:

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;//用layout来初始化布局

- (instancetype)initWithCoder:(NSCoder *)aDecoder://通过 xib 文件来初始化

- (void)registerClass:(nullable Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;//通过类来注册

- (void)registerNib:(nullable UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;//通过 xib 来注册

- (void)registerClass:(nullable Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;//用 class来注册一个带补充视图的类

- (void)registerNib:(nullable UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;//通过 xib 来注册一个带补充视图的类

- (UICollectionViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;//通过identifier来复用 cell

- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;//通过 Identifier 获取复用 ReusableView

- (NSArray<NSIndexPath *> *)indexPathsForSelectedItems;//选中的 items 的 indexPath

- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition;//指定选中的 item 的动画和位置

- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;//取消选中的 item

- (void)reloadData; //刷新数据

- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout animated:(BOOL)animated; //是否动态设置布局

- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout animated:(BOOL)animated completion:(void (^ __nullable)(BOOL finished))completion ;//是否动态设置布局并回调

- (UICollectionViewTransitionLayout *)startInteractiveTransitionToCollectionViewLayout:(UICollectionViewLayout *)layout completion:(nullable UICollectionViewLayoutInteractiveTransitionCompletion)completion;//切换 layout

- (void)finishInteractiveTransition;//layout 切换完成

- (void)cancelInteractiveTransition;//取消切换 layout

- (NSInteger)numberOfSections;//组

- (NSInteger)numberOfItemsInSection:(NSInteger)section;//每组有多少 items

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;//返回 item 的布局属性

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;//返回重用视图的布局属性

- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point;//点击的 item 的 indexpath

- (NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell;//cell 的 indexPath

- (UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath;//indexPath 对应的 cell

- (NSArray<__kindof UICollectionViewCell *> *)visibleCells;//当前可见视图 celsl 的数组

- (NSArray<NSIndexPath *> *)indexPathsForVisibleItems;//当前可见视图的 items 的 indexPath 的数组

- (UICollectionReusableView *)supplementaryViewForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath;//indexPath 对应的重用视图

- (NSArray<UICollectionReusableView *> *)visibleSupplementaryViewsOfKind:(NSString *)elementKind;//当前可见的重用视图数组

- (NSArray<NSIndexPath *> *)indexPathsForVisibleSupplementaryElementsOfKind:(NSString *)elementKind;//当前可见辅助视图的 indexPath 的数组

- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated//滚动到 indexPath 的 item;

- (void)insertSections:(NSIndexSet *)sections;//插入组

- (void)deleteSections:(NSIndexSet *)sections;//删除组

- (void)reloadSections:(NSIndexSet *)sections;//刷新某一组

- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;//移动组

- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;//插入 items

- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;//删除 items

- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;//刷新 items

- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;//移动 item

- (void)performBatchUpdates:(void (^ __nullable)(void))updates completion:(void (^ __nullable)(BOOL finished))completion;//一次性完成插入/删除等操作

- (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath ;//是否允许排序

- (void)updateInteractiveMovementTargetPosition:(CGPoint)targetPosition;//更新 item 的位置

- (void)endInteractiveMovement;//移动完成后

- (void)cancelInteractiveMovement;//取消更新(恢复到原始的位置)

UITableView

常用属性:

style:tableview 的样式

rowHeight:cell行高

sectionHeaderHeight:组头行高

sectionFooterHeight:组尾行高

estimatedRowHeight:预定义行高

estimatedSectionHeaderHeight:预定义组头高

estimatedSectionFooterHeight:预定义组尾高

separatorInset:分割线的偏移量

backgroundView:背景视图

numberOfSections:组数

visibleCells:当前可见的 cell

indexPathsForVisibleRows:可见 cell 的 indexPath

editing:编辑

allowsSelection:非编译状态下是否允许选中

allowsSelectionDuringEditing//编译状态下允许某行可以选中

allowsMultipleSelection:是否允许多选

allowsMultipleSelectionDuringEditing:在编译状态下是否允许多选

indexPathForSelectedRow:选中的 cell 的 indexPath

indexPathsForSelectedRows:选中的多个的 cell 的 indexPath

sectionIndexMinimumDisplayRowCount;显示 rowcount 的时候的最小 sectionIndex

sectionIndexColor:改变某一行的颜色

sectionIndexBackgroundColor:改变某一行的背景色

sectionIndexTrackingBackgroundColor:选中某部分的背景色

separatorColor:选中 cell 分割线的颜色

separatorEffect:毛玻璃效果

tableHeaderView:头视图

tableFooterView:尾视图

remembersLastFocusedIndexPath:记录最后一个焦点的 indexPath

常用方法:

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;带 frame 的初始化方法

- (instancetype)initWithCoder:(NSCoder *)aDecoder;//通过 IB 初始化

- (void)reloadData;//刷新数据

- (void)reloadSectionIndexTitles;//刷新索引栏

- (NSInteger)numberOfRowsInSection:(NSInteger)section;//每组有多少行

- (CGRect)rectForSection:(NSInteger)section;  //获取某个组的位置和大小

- (CGRect)rectForHeaderInSection:(NSInteger)section;//获取某个组的组头的位置和大小

- (CGRect)rectForFooterInSection:(NSInteger)section;//获取某个组的组尾的位置和大小

- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;//获取某一行的位置和大小

- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;   //由点确定在该行的 indexPath

- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;//获取 cell 的 indexPath

- (NSArray<NSIndexPath *> *)indexPathsForRowsInRect:(CGRect)rect; //获取多行的 indexPath 数组

- (__kindof UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;   //设置 cell

- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section;//设置组头

- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section;//设置组尾

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;//将某行滚动到特点位置

- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;//将选中的行滚动到特定位置

- (void)beginUpdates;//和下面方法成对使用,表示开始动态改变某一行

- (void)endUpdates;//和上面的方法成对使用,表示动态改变某行结束

- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;//动态插入一行

- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;//动态删除一组

- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;//刷新一组

- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;//移动某一组

- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;//插入多行

- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;//删除多行

- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;//刷新多行

- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;//移动某一行

- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;//选中行滚动到特定位置

- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;//取消选中

- (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;//设置 cell 的重用标识符

- (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;//设置某些 cell 的重用标识符

- (UITableViewHeaderFooterView *)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier;//设置头尾视图的重用标识符

- (void)registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier;//通过 xib注册带重用标识符的 cell

- (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier;//通过类注册带重用标识符的 cell

- (void)registerNib:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier;通过 xib 注册重用的cell头尾视图

- (void)registerClass:(nullable Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier;通过类注册重用的 cell 的头尾视图

附件:

UIScrollView,UICollectionView 和UITableView的属性和方法的更多相关文章

  1. UITableView常用属性和方法 - 永不退缩的小白菜

    UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00  博客园精华区原文  http://www.cnblogs.com/zhaofucheng11 ...

  2. 12-27 UITableView常用属性及方法

    UITableView也有自己的代理协议,它本身继承自UIScrollView 一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法: 1.改变某一行的行 ...

  3. 在UIScrollView、UICollectionView和UITableView中添加UIRefreshControl实现下拉刷新

    Apple在iOS 6中添加了UIRefreshControl,但只能在UITableViewController中使用,不能在UIScrollView和UICollectionView中使用. 从i ...

  4. UITableView的全部属性、方法以及代理方法执行顺序,看过之后肯定有收获---董鑫

    UITableView-------表视图--继承UIScrollView并遵守NSCoding协议 属性 frame-------------设置控件的位置和大小 backgroundColor-- ...

  5. [OC][转]UITableView属性及方法大全

    Tip: UITableView属性及方法大全  (摘录地址) p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 1 ...

  6. 一、UITableView的属性

    一.UITableView的属性 NSIndexPath类型是用来获取用户选择的indexPath,在别的函数里面,若需要知道用户选择了哪个cell,用上它可以省事很多.不必再去建全局变量sectio ...

  7. UIKit的外观属性及方法汇总

    本文授权转载,作者:楚天舒(简书) 开发中经常会碰到要设置UI的某个生僻的外观属性,虽然在头文件中都能查到,但一是每个控件的头文件比较分散繁杂,二是每个头文件里有太多不用到的方法和属性,所以这里将UI ...

  8. IOS开发UI基础UITableView的属性

    UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped <UITableViewDataSour ...

  9. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

随机推荐

  1. Wireshark嗅探抓取telnet明文账户密码

    0x00 Wireshark(前称Ethereal)是一个网络封包分析软件.网络封包分析软件的功能是撷取网络封包,并尽可能显示出最为详细的网络封包资料.Wireshark使用WinPCAP作为接口,直 ...

  2. Net Core Identity 身份验证:注册、登录和注销 (简单示例)

    一.前言 一般我们自己的系统都会用自己设置的一套身份验证授权的代码,这次用net core的identity来完成简单的注册.登录和注销. 二.数据库 首先就是创建上下文,我这里简单的建了Users和 ...

  3. python的变量内存管理

    一.变量的引用机制 当你在python中定义一个值,如x = 500时,python会在内存中开辟一个小地方用于存储数值. x = 500 #定义一个变量 print(id(x)) #打印该变量的内存 ...

  4. PHP yaf显示错误提示

    PHP yaf显示错误提示 1就是配置文件的那个错误 <pre>error_reporting(E_ALL);</pre> 2init.php文件的<pre>fun ...

  5. FileStream相关知识分享

    一.如何理解FIleStream 通过前3章的学些,相信大家对于Stream已经有一定的了解,但是又如何去理解FileStream呢?请看下图: 我们磁盘中的任何文件都是通过二进制数组组成,最为直观的 ...

  6. JSON《===》JavaBean的相互转换

    1.JSON的作用和好处  在JavaWeb项目中前后端直接的交互,接口之间的对接等等,基本离不开JSON. JSON: 全称JavaScript Object Notation(JavaScript ...

  7. show语句大全

    基于本人对MySQL的使用,现将常用的MySQL show 语句列举如下: 1.show databases ; // 显示mysql中所有数据库的名称 2.show tables [from dat ...

  8. Python 基础之socket编程(一)

    Python 基础之socket编程(一) 可以进行通信玩儿了,感觉不错不错,网络通信就像打电话,我说一句你听一句之后,你再说一句,我听一句,就这样.....下去了.不扯淡了,来来来,看看今天都搞了点 ...

  9. java编程思想第四版第十章总结

    1. 内部类的特性 他允许你把一些逻辑相关的类组织在一起. 2. 使用.this 如果你需要在内部类中堆外部类进行应用,可以使用外部类的名字后面加.this.下面展示了如何使用 .this packa ...

  10. 爬虫多线程模板,xpath,etree

    class QuiShi: def __init__(self): self.temp_url = "http://www.lovehhy.net/Joke/Detail/QSBK/{0}& ...