1

我正在尝试设置 custom UITableViewCells。我可以设置 backgroundView 没问题,但如果我设置selectedBackgroundView,单元格的背景变成白色,只看到选定的背景:

- (void) createCell: (UITableViewCell*)cell onRow: (NSUInteger)row
{
UIImageView* bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_background_red.png"]];
cell.backgroundView = bgImage;
cell.selectedBackgroundView = bgImage;
cell.textLabel.hidden = YES;

UILabel* titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(20, CGRectGetHeight(cell.frame) / 2, 200, 50)];
titleLabel.text = [[self.ruleList objectAtIndex: row] objectForKey: TitleKey];
titleLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: titleLabel];

}
4

1 回答 1

3

You are setting the same image for both backgroundView and selectedBackgroundView.

cell.backgroundView = bgImage;
cell.selectedBackgroundView = bgImage;

when you do like this, both are overlapped and results in a white colored background or you could see only the background selected view.

于 2012-10-07T09:33:52.930 回答