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

一、统一设置tableview的头部和尾部的高度
33.png
    // 设置头部间距
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = ZSCommonMargin;

问题:设置完成后,头行上面的间距比较大

55.png

解决方法如下:

  1. 先调用这个方法,计算cell的frame
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];  
        ZSLog(@"%@",NSStringFromCGRect(cell.frame));
}
11.png

2.由此可知y值为35。通过contentInset(内边距)进行设置。

  // 设置内边距(-25代表:所有内容往上移动25)
 self.tableView.contentInset = UIEdgeInsetsMake(ZSCommonMargin - 35, 0, 0, 0);

最终效果图:

7.png

二、分别设置不同的头部和尾部的高度
-(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;
    
    
}

*设置头部、尾部的内容

44.png

其它正在整理中

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容