Iphone 是否可以更改UITableView节标题背景颜色

Iphone 是否可以更改UITableView节标题背景颜色,iphone,uitableview,Iphone,Uitableview,作为标题,可以这样做吗?您需要使用 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 30; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *v = [[UIVie

作为标题,可以这样做吗?

您需要使用

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section       
{
    UIView *v = [[UIView alloc] init];
    [v setBackgroundColor:[UIColor blackColor]];
    return [v autorelease];
}
这是免费的,所以请原谅任何打字错误等


更新:这仅适用于“分组”表。您的桌子是分组的还是普通的?

是。使用UITableViewDelegate协议中的方法自定义标题部分:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
当它返回UIView时,您可以将其设置为任何您喜欢的或只是

[UIView setBackgroundColor:UIColor]