iphone - 细胞背景及配件

标签 iphone sdk uitableview accessoryview

我正在尝试设置 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];
}

这是说明问题的图片

UIAccessoryView does not change background color.

最佳答案

您需要设置 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/

相关文章:

json - 为什么我的 json 不会将列表中的所有对象解析为带有标题的不同行?

iphone - PhoneGap 3/Cordova 3 不使用 native 邮件应用程序 (ios) 打开电子邮件链接 (mailto)

iphone - PerformSelector After delay 不在后台模式下运行 - iPhone

iphone - 保留CGPath对象时遇到麻烦(出现警告)

python - azure-sdk-for-python : get list of managed disks from a specified resource group

ios - AccessibilityElements 在 TableView 中不起作用

iphone - navigationController popToRootViewController 和 viewWillDisappear

android - 一些Android的音板上的ForceClose问题?

c# - 从 Azure Active Directory 获取最近添加/更新的用户

ios - 每 10 个单元格重复 TableView