更改分组的UITableView的背景

我遇到了一些麻烦,试图改变与组的背景UITableView。

_tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableViewBg.png"]]; 

这通常适用于所有其他的UITableView,但不是有组的,还有其他的我需要做的吗? 在IB中,我将背景颜色设置为一个清晰的颜色,但是这并没有太大的作用。

您还需要禁用_tableView的背景视图:

 [_tableView setBackgroundView:nil]; _tableView.backgroundColor = [UIColor redColor]; 

无需为backgroundView添加新的视图。 这在iOS6适用于我。

你为什么不设置tableView.backgroundView? 您可以使用指定的图像分配一个图像视图,并将其传递到背景视图,而不是设置背景颜色。

我通常用分组的UITableViews做的事情是设置背景颜色清除,并设置模式图像的父母查看。

 self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableBG.png"]]; self.tableView.backgroundColor = [UIColor clearColor]; 

所选答案的作品,但清除tableHeaderView和表部分标题视图的背景。 如果你只是希望表头是一个特定的颜色说白色和部分标题仍然是默认的灰色比以下 –

 tableView.tableHeaderView.inputView.backgroundColor = [UIColor whiteColor]; 

只是想添加到Nirav的答案 – 它也可以使用iOS 5外观代理。

 [[UITableView appearance] setBackgroundView:nil]; [[UITableView appearance] setBackgroundColor:[UIColor lightGreyColor]]; 

好处是它适用于全球,所以你可以把你所有的用户界面定制在一个地方。 但是,它将适用于所有tableViews(不只是分组样式)。

 tableView.backgroundView = nil; tableView.backgroundColor = [UIColor colorWithPatternImage: xxx]; // tableView.backgroundColor = [UIColor redColor]; // is ok 

如果将此设置为backgroundColor,则在滚动tableView时,backgroundColor视图也将滚动。 所以,你可以:tableView.backgroundView = nil; self.view.backgroundColor = …