UITableViewCellStyleSubtitle标签的BackgroundColor? [英] BackgroundColor of UITableViewCellStyleSubtitle labels?
问题描述
我正在尝试创建一个以图像为背景的表格. 为此,我从背景入手:
I am trying to create a table with an image as a background. To achieve this, I started out with the background:
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
这导致背景图像也出现在表格单元格中.那不是我想要的东西,所以我尝试设置单元格的backgroundColor:
This resulted in a background image which appears in tablecells as well. That is not something I want, so I tried to set the cell's backgroundColor:
cell.backgroundColor = [UIColor whiteColor];
这根本没有效果!!!嗯,很奇怪. 所以我尝试了这个:
This had no effect at all !!!. Hmmm strange. So I tried this:
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = backgroundView;
[backgroundView release];
这几乎可行.剩下的唯一问题是textLabel& detailTextLabel仍显示它们后面的背景. 将这些标签上的backgroundColor设置为白色也无济于事.
This works almost. The only problem left is that the textLabel & the detailTextLabel still show the background behind them. Setting the backgroundColor on those labels to white doesn't do anything either.
我该如何进行?我哪里出问题了?我正在尝试实现像worldClock应用程序一样的tableView.
How do I proceed? Where do I go wrong? I am trying to achieve a tableView like the worldClock app has.
推荐答案
要更改表格视图单元格的背景色,您需要将其设置为tableView:willDisplayCell:forRowAtIndexPath:
而不是tableView:cellForRowAtIndexPath:
否则不会有任何效果,例如:
To change the background colour of the table view cell, you'll need to set it in tableView:willDisplayCell:forRowAtIndexPath:
rather than tableView:cellForRowAtIndexPath:
otherwise it won't have any effect, for example:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor whiteColor];
}
这篇关于UITableViewCellStyleSubtitle标签的BackgroundColor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!