我正在尝试设置我的UITableViewCells的单元格背景,但我正在为UIAccessoryView的背景颜色而苦苦挣扎。它不会改变。
有没有人能帮我把UIAccessoryView的背景颜色改成透明的(或者其他颜色)?
这是我的代码
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.accessoryView.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(indexPath.row % 2) {
cell.contentView.backgroundColor = [UIColor clearColor];
}
else {
cell.contentView.backgroundColor = [UIColor redColor];
}这是一张说明这个问题的图片

发布于 2011-03-19 18:20:05
您需要设置UITableViewCell的backgroundView属性。例如:
UIView* myBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
myBackgroundView.backgroundColor = [UIColor redColor];
myCell.backgroundView = myBackgroundView;如果你想要一些更花哨的东西,比如红色渐变背景,你可以实现一个在drawRect:中绘制渐变的UIView子类,并将其用作backgroundView。
如果需要选定表单元格的自定义外观,也可以设置selectedBackgroundView属性。
发布于 2012-11-29 20:49:08
在函数中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath使用以下代码
cell.contentView.superview.backgroundColor = [UIColor redColor];发布于 2016-04-10 09:51:44
如果你想在UITableViewCell的自定义类中修改它,你只需要使用:
override func layoutSubviews() {
super.layoutSubviews()
self.backgroundColor = UIColor.whiteColor()
}在awakeFromNib()或init?(coder aDecoder: NSCoder)中更改背景不起作用!
https://stackoverflow.com/questions/5361408
复制相似问题