2011-04-13 28 views
6

我知道这可能已经问十万的时候,我试图通过以下改变了我的UITablewViewCell背景:改变UITableViewCell的背景

cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1]; 
       cell.textLabel.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1]; 

,所有我现在是:

enter image description here

如何设置附件视图的背景颜色?

UPDATE: 我的顶端有一个节头,其中有一个白色的背景

回答

13

将这个在您的UITableViewDelegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1]; 
} 
+0

这是否改变了部分呢? – aherlambang 2011-04-14 01:45:08

+0

它不应该改变部分的颜色,你必须通过实现'tableView:viewForHeaderInSection:'并且返回你自己的视图。 – conmulligan 2011-04-14 16:03:43

+0

这是许多为我工作的唯一解决方案。非常感谢 – almas 2013-03-30 03:47:37

0

你是过于复杂了一下它。你可以改变桌面视图的背景颜色,这正是你想要的。这样,您不必为每个单元格设置颜色。 :)

self.tableView.backgroundColor = [UIColor greenColor]; 
+0

我实际上有一个部分在顶部,我不想有蓝色背景..应该显示在屏幕截图 – aherlambang 2011-04-14 01:45:47

+0

您可以添加屏幕截图到您的文章? 你是在谈论表视图标题视图? – 2011-04-14 21:43:26

-3
//in willDisplayCell 
if (indexPath.section > 0) { 
    cell.backgroundColor = [UIColor blueColor]; 
}