[英]UITableViewCell with accessory
I got an app with UITableView. 我有一个使用UITableView的应用程序。 Every cell has accessory. 每个细胞都有配件。 But i cant set backgroundColor ti this cells. 但我不能设置backgroundColor ti这个单元格。
I tried to set backgrounColors in this ways: 我尝试以这种方式设置backgrounColors:
cell.contentView.backgroundColor =[UIColor redColor];
cell.backgroundView.backgroundColor = [UIColor redColor];
cell.backgroundColor = [UIColor redColor];
But only contentView work. 但只有contentView工作。 How can i do it? 我该怎么做? Thnx 日Thnx
the second way cell.backgroundView.backgroundColor = [UIColor redColor];
第二种方式cell.backgroundView.backgroundColor = [UIColor redColor];
is not that wrong. 没错。 Unfortunately there is no backgroundView until you create one. 不幸的是,在你创建一个后,没有backgroundView。 You have to create an UIView and set it as background of the cell. 您必须创建一个UIView并将其设置为单元格的背景。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
UIView *background = [[UIView alloc] initWithFrame:CGRectZero];
background.backgroundColor = [UIColor redColor];
cell.backgroundView = background;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.