0

我正在尝试为 UITableView 自定义节标题。UITableView 是在 IB 中创建的。我有两个我无法弄清楚的问题。

  1. 无论 UILabel 有多大,字体大小都不会超过 18 左右。

  2. 部分标题遮盖了表格。

我把标签涂成蓝色,这样你就可以看到它们的大小。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// Name of section
NSString *header = [[purchases allKeys] objectAtIndex:section];

// Label for section header
UILabel *label = [[[UILabel alloc] init] autorelease];
label.frame = CGRectMake(10, 0, 230, 45);
label.textColor = _orange;
label.font = [UIFont fontWithName:@"Heiti TC Medium" size:52];
label.text = header;
label.backgroundColor = [UIColor blueColor];

// View to contain label
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 230, 45)];
[view autorelease];
[view addSubview:label];

return view;
}

截屏

4

1 回答 1

1
  1. 您应该为标题高度添加表视图委托方法
  2. 您应该将所有单元格宽度用于标题视图。
  3. 您的字体命名为 STHeitiTC-Medium
于 2012-10-16T23:24:32.250 回答