使用tableView的UITableViewStyleGrouped样式时

本文介绍了如何在UITableView中设置section的Header和Footer,并提供了具体的实现代码。此外,还介绍了如何调整Footer的高度来隐藏它。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

它是由两部分组成的,上一个section的footer和下一个section的header。通过以下代码就很明显

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, ScreenW, 20);

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    label.center = CGPointMake(ScreenW/2, 20/2);
    label.font = [UIFont systemFontOfSize:12];
    label.backgroundColor = [UIColor redColor];
    label.textAlignment = NSTextAlignmentCenter;
    [view addSubview:label];
    if (section == 0) {
        label.text =  @"最后更新时间:";
    }else
    {


 


        label.text =@"配置信息";
    
    }
    
    
    
    return view;

}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, ScreenW, 20);
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    label.center = CGPointMake(ScreenW/2, 20/2);
    label.font = [UIFont systemFontOfSize:12];
    label.backgroundColor = [UIColor blueColor];
    label.textAlignment = NSTextAlignmentCenter;
    [view addSubview:label];
    return view;
}

若想去掉section的footer,仅设置:应将其高度设为比1小很多,但不为0的值,才会有效果

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return 0.001f;

}

转载于:https://www.cnblogs.com/dcy123/p/5895115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值