【问题标题】:iOS - Custom section header bounds issueiOS - 自定义部分标题边界问题
【发布时间】:2012-02-27 21:21:00
【问题描述】:

我正在尝试为我的分组单元格创建我自己的部分标题。当我使用以下代码创建它时,它看起来好像边界已关闭。更具体地说,CGRect 的高度

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *header = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 50)] autorelease];
    [header setBackgroundColor:[UIColor clearColor]];

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width, 18)] autorelease];
    label.textColor = [UIColor redColor];
    label.text = @"SOME TEXT";
    label.backgroundColor = [UIColor clearColor];

    [header addSubview:label];

    return header;
}

知道为什么高度不对吗?我错过了什么吗?

【问题讨论】:

    标签: ios cgrect uitableview


    【解决方案1】:

    您是否还按照文档中的说明实现了tableView:heightForHeaderInSection:?这应该为您的表返回 50。

    【讨论】:

    • 正是我所缺少的。谢谢好心的先生!
    【解决方案2】:

    只是好奇你为什么不定义 TableView 类型(分组),在 IB 中设置节标题的属性然后使用:

    - (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    

    【讨论】:

    • 我之前确实使用过这种方法,但是我无法更改文本颜色。
    猜你喜欢
    • 2020-05-27
    • 1970-01-01
    • 2013-03-14
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    相关资源
    最近更新 更多