我有一個問題,其中設置我的tableView的背景顏色覆蓋我爲單個單元格設置的背景顏色。更具體地講,我有3行的表:頂部細胞是暗灰色,底部2個細胞是紅:iOS UITableView:改變表格的背景顏色覆蓋單元格的背景顏色
http://imgur.com/otYlFMx,LvoLDzY,tXiJenw#0
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
UIColor *sectionBackgroundColor = [UIColor colorWithRed:0.09f green:0.09f blue:0.09f alpha:1.0];
UIColor *menuItemBackgroundColor = [UIColor redColor];
if (indexPath.row == 0) {
cell.backgroundColor = sectionBackgroundColor;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = @"MENU";
cell.textLabel.font= [UIFont systemFontOfSize:16.0];
cell.selectionStyle = false;
} else if (indexPath.row == 1) {
cell.backgroundColor = menuItemBackgroundColor;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = @"Schedule";
cell.textLabel.font= [UIFont systemFontOfSize:18.0];
cell.imageView.image = [UIImage imageNamed:@"Schedule.png"];
} else if (indexPath.row == 2) {
cell.backgroundColor = menuItemBackgroundColor;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = @"Contacts";
cell.textLabel.font= [UIFont systemFontOfSize:18.0];
cell.imageView.image = [UIImage imageNamed:@"Contacts.png"];
} else {
cell.backgroundColor = [UIColor blackColor];
cell.selectionStyle = false;
}
}
我想要做的就是讓所有底部黑色的那些空的,未使用的白色細胞。根據我的研究,設置的tableView背景顏色將做到這一點:
http://imgur.com/otYlFMx,LvoLDzY,tXiJenw#1
tableView.backgroundColor = [UIColor blackColor];
然而,當你注意到沒有,這行代碼改變了前兩名單元格的背景顏色爲黑色了。我打得四處這個越來越注意到,每一個單元格的背景顏色將變爲黑色,除了最後一個通用的模式:對於所發生的事情
(見上面的鏈接3圖像)
任何想法這裏?幫助將不勝感激!
有些事情我已經試過,不工作(我會提供更多的聯繫,但我現在代表不允許我):
a)提出的意見細胞不透明。更改單元格中不同視圖的顏色。
cell.opaque = YES;
cell.backgroundView.opaque = YES;
cell.contentView.opaque = YES;
cell.backgroundColor = menuItemBackgroundColor;
cell.contentView.backgroundColor = menuItemBackgroundColor;
cell.backgroundView.backgroundColor = menuItemBackgroundColor;
B)設置tableView的backgroundView無。
tableView.backgroundView = nil;
C)設置tableView的backgroundView背景顏色。
tableView.backgroundView.backgroundColor = [UIColor blackColor];
backgroundView默認爲零,所以cell.backgroundView.backgroundColor = menuItemBackgroundColor;除非您添加了背景視圖,否則不會執行任何操作。 – rdelmar