我的标签有问题
UITableViewCell
阻止背景图像。似乎它只发生在未选择的状态。我试着将背景色设置为清晰,但没有做到。它采用了TableView的背景色。我也必须设置标签背景图像吗?
// Neither of these worked...
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
这是我的
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableIdentifier"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SimpleTableIdentifier"] autorelease];
}
UIImage *image = [UIImage imageNamed:@"TableRow.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleToFill;
cell.backgroundView = imageView;
[imageView release];
UIImage *imageSelected = [UIImage imageNamed:@"TableRowSelected.png"];
UIImageView *imageViewSelected = [[UIImageView alloc] initWithImage:imageSelected];
imageViewSelected.contentMode = UIViewContentModeScaleToFill;
cell.selectedBackgroundView = imageViewSelected;
[imageViewSelected release];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = [[self.trivia.questionsets objectAtIndex:indexPath.row] valueForKeyPath:@"title"];
return cell;
}
更新
:有点解决了……
如果我将表的背景色(我假设它位于所有内容的下面)设置为清除,那么突然间,我的图像显示了我所期望的位置,但表的背景现在显示在所有内容的顶部?这是预期的行为吗?(还没有检查文档)
tableView.backgroundColor = [UIColor redColor];
cell.contentView.backgroundColor = [UIColor orangeColor];
cell.textLabel.backgroundColor = [UIColor yellowColor];
…最后,如果我将表格和单元格的背景色都设置为“清除”,我们就很好了。textLabel背景色没有区别。
tableView.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor yellowColor];