iOS - 自定义节标题边界问题

标签 ios cgrect uitableview

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

的高度

enter image description here

- (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;
}

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

最佳答案

您是否还按照文档中的描述实现了 uitableView:heightForHeaderInSection: ?这将为您的表返回 50。

关于iOS - 自定义节标题边界问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9472468/

相关文章:

ios - 如何将 UIPickerView Controller 中的图像或视频保存到文档目录?

ios - 以编程方式处理 View 调整高度、宽度和边距

c - 将一个矩形拆分成大小相等的矩形?

swift - 导航回 tableview View Controller 时更新 tableview 而不是整个重新加载

css - 如何将颜色代码转换为实际颜色

ios - 从 Swift 中的背景颜色确定文本颜色?

objective-c - 在 numberOfRowsInSection 中调用 TableView BeginUpdates

ios - UIView 动画将 View 重置为原始矩形

ios - 来自不同部分的 TableView 单元格混合在一起

ios - 将 json 字典保存到核心数据 Swift 3