UITableView實(shí)戰(zhàn)總結(jié)(三)——HeaderInSection、FooterInSection和tableHeaderView、tableFooterView

一、HeaderInSection、FooterInSection

1、HeaderInSection(對(duì)Section的Header的內(nèi)容和高度的設(shè)置)

  • 不顯示Header(隱藏頂部分隔線)
 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 { 
     return 0.001;
 }
  • 需要設(shè)置和顯示Header的內(nèi)容與高度
 // 設(shè)置Header內(nèi)容
 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
 {
     UIView *view = [[UIView alloc] init];
     view.backgroundColor = [UIColor whiteColor];
     return view;
 }

 // 返回Header高度
 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 {
     return 10;
 }

2、FooterInSection(對(duì)Section的Footer的內(nèi)容和高度的設(shè)置)

  • 不顯示Footer(隱藏底部分隔線)
 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
 {
     return 0.001;
 }
  • 需要設(shè)置和顯示Footer的內(nèi)容與高度
 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
 {
     UIView *view = [[UIView alloc] init];
     view.backgroundColor = [UIColor whiteColor];
     return view;
 }

 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
 {
     return 60;
 }

二、tableHeaderView、tableFooterView

1、tableHeaderView

  • headerView的申明
@property (nonatomic,strong) UIView *headerView;
  • 在tableView初始化時(shí)調(diào)用
_tableView.tableHeaderView = self.headerView;
  • 創(chuàng)建方法
 - (void)createTableHeaderView
 {
     CGRect frame = CGRectMake(0, 0, ScreenWidth, 10);
     self.headerView = [[UIView alloc] initWithFrame:frame];
     self.headerView.backgroundColor = [UIColor whiteColor];
 }

2、tableFooterView

  • footerView的申明
@property (nonatomic,strong) UIView *footerView;
  • 在tableView初始化時(shí)調(diào)用
_tableView.tableFooterView = self.footerView;
  • 創(chuàng)建方法
 - (void)createTableFooterView
 {
     CGRect frame = CGRectMake(0, 0, ScreenWidth, 60);
     self.footerView = [[UIView alloc] initWithFrame:frame];
     self.footerView.backgroundColor = [UIColor whiteColor];
     [self.footerView addSubview:self.button];
 }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 版權(quán)聲明:未經(jīng)本人允許,禁止轉(zhuǎn)載. 1. TableView初始化 1.UITableView有兩種風(fēng)格:UITa...
    蕭雪痕閱讀 2,990評(píng)論 2 10
  • 概述在iOS開(kāi)發(fā)中UITableView可以說(shuō)是使用最廣泛的控件,我們平時(shí)使用的軟件中到處都可以看到它的影子,類(lèi)似...
    liudhkk閱讀 9,299評(píng)論 3 38
  • UITableView 是 iOS 開(kāi)發(fā)中必不可少的一個(gè)控件,基本上每一個(gè)項(xiàng)目都會(huì)有多個(gè)地方會(huì)用到。詳細(xì)的了解UI...
    破夕_____________閱讀 2,228評(píng)論 0 4
  • UITableView有兩種樣式: UITableView的結(jié)構(gòu):UITableView由頭部,尾部,和中間一連串...
    degulade閱讀 931評(píng)論 1 3
  • 三年級(jí)的第一個(gè)感受,早上去學(xué)校,我去吃粉,小姑娘可以自己走路進(jìn)學(xué)校,也會(huì)主動(dòng)跟值日老師打招呼。 開(kāi)學(xué)典禮上,蝸牛與...
    木木王_deb5閱讀 299評(píng)論 0 0

友情鏈接更多精彩內(nèi)容