iphone分组uitableview标题字体样式

时间:2010-08-28 11:40:14

标签: iphone uitableview

我在更改分组的uitableview的节标题时遇到问题。我尝试了一切。我想知道这是模拟器的错误还是什么?我正在运行最新版本的xcode,正在为iPad开发。

这是我的tableview标题代码

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

    UILabel *label = [[[UILabel alloc] init] autorelease];
    label.frame = CGRectMake(20, 6, 300, 30);
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor grayColor];
    label.shadowOffset = CGSizeMake(0.0, 1.0);
    label.font = [UIFont boldSystemFontOfSize:14];
    label.text = @"hello"; //sectionHeader;

    return label;

}

当我编译时,它只显示没有标题。我也试图在这里添加一个视图,根据下面的代码

UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
sectionView.backgroundColor = [UIColor redColor];
[sectionView autorelease];
[sectionView addSubview:label];
return sectionView;

我做错了吗?

1 个答案:

答案 0 :(得分:5)

来自the documentation

  

[tableView:viewForHeaderInSection:]仅在tableView:heightForHeaderInSection:同时实施时才能正常工作。