2011-04-13 57 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]; 
}