Objective c 设置UITableView节标题的颜色

Objective c 设置UITableView节标题的颜色,objective-c,xcode,uitableview,uicolor,Objective C,Xcode,Uitableview,Uicolor,如何将我的所有分区的分区标题设置为红色,而不将它们设置为具有所有相同的标题字符串,以及如何设置字体和字体颜色 我试过这个,但它摆脱了我的部分标题 - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bou

如何将我的所有分区的分区标题设置为红色,而不将它们设置为具有所有相同的标题字符串,以及如何设置字体和字体颜色

我试过这个,但它摆脱了我的部分标题

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
    if (section == 1)
        [headerView setBackgroundColor:[UIColor redColor]];
    else
        [headerView setBackgroundColor:[UIColor clearColor]];
    return headerView;
}
我将非常感谢一些示例代码


提前感谢

尝试自定义您的节标题视图。您可以扩展此方法

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UILabel *headerView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];

    //Put your common code here
    // lets say you need all background color to be white. do this here
     [headerView setBackgroundColor:[UIColor redColor]];

    //Check the section and do section specific contents
    if (section == 1)
        [headerView setText:@"Section 1"];
    else
        [headerView setBackgroundColor:[UIColor clearColor]];

  return headerView;

}

如果您只是想更改标题视图的背景和字体颜色,一种更简单的方法可能是使用

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

这里有一个很好的例子/解释。

我们希望能有一些代码来展示您的尝试。@vikingosegundo,你看,goDamn——我不知道!
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {

    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    header.textLabel.textColor = [UIColor redColor];
    CGRect headerFrame = header.frame;
    header.textLabel.frame = headerFrame;
    [header.contentView setBackgroundColor:[UIColor blueColor]];
}