12-TableView的頭部和尾部的高度

一、統(tǒng)一設(shè)置tableview的頭部和尾部的高度
33.png
    // 設(shè)置頭部間距
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = ZSCommonMargin;

問題:設(shè)置完成后,頭行上面的間距比較大

55.png

解決方法如下:

  1. 先調(diào)用這個方法,計算cell的frame
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];  
        ZSLog(@"%@",NSStringFromCGRect(cell.frame));
}
11.png

2.由此可知y值為35。通過contentInset(內(nèi)邊距)進(jìn)行設(shè)置。

  // 設(shè)置內(nèi)邊距(-25代表:所有內(nèi)容往上移動25)
 self.tableView.contentInset = UIEdgeInsetsMake(ZSCommonMargin - 35, 0, 0, 0);

最終效果圖:

7.png

二、分別設(shè)置不同的頭部和尾部的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) return 10;
    if (section == 1) return 20;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) return 10;
    if (section == 1) return 20;
    
    
}

*設(shè)置頭部、尾部的內(nèi)容

44.png

其它正在整理中

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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