开发者社区> 问答> 正文

关于 tableView自定义Header出现个问题

screenshot

如上图,在第一个section它的头部比其他section大,只是为何?如何解决?
相关代码

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    // Create label with section title
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake((SCREEN_WIDTH-200)/2, 10, 200, 25);
    label.backgroundColor = [UIColor clearColor];
    label.textColor = BarCOLOR;
    label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = sectionTitle;

    // Create header view and add label as a subview
    UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)];
    [sectionView setBackgroundColor:[UIColor blackColor]];
    [sectionView addSubview:label];
    return sectionView;

    return nil;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"12232211";
}

展开
收起
爵霸 2016-03-06 14:47:16 2052 0
1 条回答
写回答
取消 提交回答
  • (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
    return 22;
    }
    
    (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
    return 0.1;
    }
    2019-07-17 18:54:35
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载