1
我试图设置自定义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];
}
因为您正在为backgroundView和selectedBackgroundView设置相同的图像。 – Charan
@sreecharan welp那工作。我只是做了这个测试,但显然测试不好-__-谢谢 – Chris
你也没有设置单元格或ImageView的帧。做initWithFrame而不是initWithImage然后imageView.image ... – xCoder