樣式
當(dāng)tableView的樣式為UITableViewPlain時
默認(rèn)沒有tableHeaderView售睹,tableFooterView,sectionHeaderView狭郑,sectionFooterView沛申。當(dāng)tableView的樣式為UITableViewGrouped時
使用默認(rèn)的高度設(shè)置tableHeaderView郁岩,tableFooterView,sectionHeaderView睦尽,sectionFooterView器净。
設(shè)置seciotnHeader或seciotnFooter的高度
1.使用屬性設(shè)置seciotnHeader或seciotnFooter的高度
當(dāng)tableView的樣式為UITableViewPlain時
屬性@property(nonatomic) CGFloat sectionHeaderHeight;
和@property(nonatomic) CGFloat sectionFooterHeight;
都不起作用。當(dāng)tabaleView的樣式為UITableViewGrouped時
屬性@property(nonatomic) CGFloat sectionHeaderHeight;
和屬性@property(nonatomic) CGFloat sectionFooterHeight;
才起作用当凡。
如果同時實(shí)現(xiàn)了代理方法tableView:heightForHeaderInSection:
或
tableView:heightForFooterInSection:
時山害,則代理方法會覆蓋屬性。當(dāng)tableView的樣式為UITableViewGrouped時
當(dāng)想設(shè)置header或footer的高度為0時沿量,只能使用屬性設(shè)置浪慌。
使用代理方法tableView:heightForHeaderInSection:
不起作用,系統(tǒng)會使用默認(rèn)高度設(shè)置header或footer朴则。
2.使用代理方法設(shè)置seciotnHeader或seciotnFooter的高度
當(dāng)tableView的樣式是UITableViewPlain時权纤,可以使用代理方法
tableView:heightForHeaderInSection:
或tableView:heightForFooterInSection:
設(shè)置header或footer高度當(dāng)tableView的樣式是UITableViewGrouped時,無法使用代理方法
tableView:heightForHeaderInSection:
或tableView:heightForFooterInSection:
設(shè)置header或footer的高度乌妒。
自定義sectionHeader或sectionFooter的視圖
*只有實(shí)現(xiàn)了方法:tableView:heightForHeaderInSection:
或tableView:heightForFooterInSection:
時汹想,設(shè)置header或footer的方法tableView: viewForHeaderInSection:
或tableView: viewForFooterInSection:
才起作用。
分割線
當(dāng)tableView的樣式為UITableViewPlain時撤蚊,table的各個cell的底部都有分割線古掏。
當(dāng)tableView的樣式為UITableViewPlain時,
如果實(shí)現(xiàn)代理方法tableView:heightForHeaderInSection:
時侦啸,
section的最后一個footer會有分割線槽唾,其他的header和footer都沒有分割線。如果實(shí)現(xiàn)代理方法
tableView:heightForFooterInSection:
時光涂,section的header和footer都沒有分割線庞萍。當(dāng)tableView的樣式為UITableViewGrouped時
section的header和footer都有一條完整的分割線。
tableHeaderView和tableFooterView
當(dāng)tableView的樣式為UITableViewStylePlain時顶捷,
可以使用self.tableView.tableFooterView = [UIView new];設(shè)置tablefooterView挂绰。
這能夠刪除tableView最底部的格外的分割線屎篱。當(dāng)tableView的樣式為UITableViewStyleGrouped時服赎,self.tableView.tableFooterView = [UIView new];和self.tableView.tableHeaderView = [UIView new];不起作用葵蒂。因?yàn)橄到y(tǒng)檢測到高度為0時,會使用默認(rèn)高度重虑。
刪除底部分割線
- 當(dāng)tableView的樣式為UITableviewPlain時践付,
tableView底部會有額外的分割線,有兩種方法可以刪除額外的分割線:
1.設(shè)置seciotnfooterView缺厉,可以刪除所有section的header和footer的分割線
2.self.tableView.tableFooterView = [UIView new];刪除底部分割線
sectionHeader和sectionFooter的浮動效果
- tableView的樣式為UITableViewStylePlain的時候永高,secitonHeader和sectionFooter會浮動,而在樣式為UITableViewStyleGrouped的時候提针,則不會命爬。
背景色
當(dāng)tableView的樣式為UITableViewPlain時,tableView沒有背景色辐脖。我并沒有設(shè)置cell的背景色饲宛,但我明白cell為何會有一個白色的背景顏色。
當(dāng)tableView的樣式為UITableViewGrouped時嗜价,tableView為所有的cell提供默認(rèn)的背景顏色和背景視圖艇抠。可以通過方法
[UIColor groupTableViewBackgroundColor]
來獲得該背景顏色久锥。
背景視圖為特定section中的所有cell提供可視分組
層次結(jié)構(gòu)
- 此外在tableView上家淤,還有一個UITableViewWrapperView,UITableViewWrapperView之上才是我們的UITableViewCell瑟由。