在section中更改titleFor Header的颜色

Ale*_*eep 4 iphone objective-c ios

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

{

}
Run Code Online (Sandbox Code Playgroud)

嗨,
我在目标c中非常新......通过这种方法,我们可以得到标题部分的标题.但是如何改变颜色那串?我可以这样做........如果有人知道的话请告诉我.

问候

Pav*_*nko 5

您可以尝试下面的内容: 带有两个自定义标签的标头

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

    NSString *dateStr = [[self.data allKeys] objectAtIndex:section];
    CGFloat labelWidth = tableView.bounds.size.width / 2;
    CGFloat padding = 5.0;

    UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake
                        (padding, 0, (labelWidth - padding), 22)];
    labelOne.backgroundColor = [UIColor clearColor];
    labelOne.textAlignment = UITextAlignmentLeft;
    labelOne.text = dateStr;

    UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectMake
    (labelWidth, 0, (labelWidth - padding), 22)];
    labelTwo.backgroundColor = [UIColor clearColor];
    labelTwo.textAlignment = UITextAlignmentRight;
    labelTwo.text = @"This is Label TWO";

    [headerView addSubview:labelOne];
    [headerView addSubview:labelTwo];

    [labelOne release];
    [labelTwo release];

    return headerView;
}
Run Code Online (Sandbox Code Playgroud)