我正在尝试设置 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];
}
这是说明问题的图片
最佳答案
您需要设置 UITableViewCell 的 backgroundView
属性。例如:
UIView* myBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
myBackgroundView.backgroundColor = [UIColor redColor];
myCell.backgroundView = myBackgroundView;
如果你想要一些更奇特的东西,比如红色渐变背景,你可以实现一个 UIView 的子类,在 drawRect:
中绘制渐变,并将其用作背景 View 。
如果您希望选定的表格单元格具有自定义外观,您还可以设置 selectedBackgroundView
属性。
关于iphone - 细胞背景及配件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5361408/