在ios开发中,tableView几乎是我们最常用到的几种控件之一了,但是对于初学者来说。常常会对contentSize、contentOffset、contentInset三个概念模糊不清,以下是自己这三个属性的自我理解(仅针对垂直方向):
一、基本概念的认识:
1.什么是tableView的内容(content):
包括三个方面分别是:cell、tableFooterView/tableHeaderView、sectionHeader/sectionFooter
2.contentSize.height:内容的高度
3.什么是内容的偏移量(offset):
内容的偏移量 = frame的顶部 - content的顶部
4.contentInset:内容周围的间距(内边距)
5.Frame
Frame.height:矩形框的高度
frame:以父控件内容的左上角为原点
二、认识进阶:
1.没有cell、没有contentInset、没有tableHeaderView和tableFooterView
![](https://img.haomeiwen.com/i1666265/5e5e6c26afb4f266.png)
2.没有cell、没有contentInset、有tableHeaderView和tableFooterView
![](https://img.haomeiwen.com/i1666265/814ca6df730da325.png)
3.有cell、没有contentInset、没有tableHeaderView和tableFooterView
![](https://img.haomeiwen.com/i1666265/868f81544c1274ef.png)
4.有cell、有contentInset、没有tableHeaderView和tableFooterView
![](https://img.haomeiwen.com/i1666265/67520d088ae79119.png)
5.有cell、没有contentInset、有tableHeaderView和tableFooterView
![](https://img.haomeiwen.com/i1666265/28f08198b38c8416.png)
6.有cell、有contentInset、有tableHeaderView和tableFooterView
![](https://img.haomeiwen.com/i1666265/89a35d1beea38ac8.png)
7.没有cell、没有contentInset、有tableHeaderView和tableFooterView、有额外子控件{0、-40、375、40}
![](https://img.haomeiwen.com/i1666265/a65142449e4673b4.png)
8.没有cell、没有contentInset、没有tableHeaderView和tableFooterView、有额外子控件{0、-40、375、40}
![](https://img.haomeiwen.com/i1666265/2dad08badddaa695.png)
9.有cell、没有contentInset、有tableHeaderView和tableFooterView、有额外子控件{0、-40、375、40}
![](https://img.haomeiwen.com/i1666265/eb586b58b52f7b0f.png)
10.有cell、有contentInset、有tableHeaderView和tableFooterView、有额外子控件{0、-40、375、40}
![](https://img.haomeiwen.com/i1666265/8c95b901c66d2cab.png)
网友评论