【问题标题】:How to change UITableViewCellAccessoryType.Checkmark's color?如何更改 UITableViewCell AccessoryType.Checkmark 颜色?
【发布时间】:2015-06-10 17:04:53
【问题描述】:

这是我的代码:

cell.accessoryType = UITableViewCellAccessoryType.Checkmark

但是当我运行应用程序时,我看不到复选标记。

然后我将背景颜色设置为黑色,我可以看到一个白色的复选标记。

如何将复选标记的颜色更改为蓝色等其他颜色?

【问题讨论】:

标签: swift uitableview checkmark


【解决方案1】:

是的,你可以做到。

只需设置单元格的tintColor

cell.tintColor = UIColor.whiteColor()
cell.accessoryType = UITableViewCellAccessoryType.Checkmark

斯威夫特 3

let aCell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
aCell.tintColor = UIColor.red
aCell.accessoryType = .checkmark
return aCell

您也可以通过 Attributes Inspector 进行操作

【讨论】:

  • 对不起@Ashish Kakkad,您的解决方案与复选标记附件配合得很好,但Apple 在披露附件方面存在问题。没有解决方案适用于披露。 (A改变了我对你的投票)=]
  • @HenriqueGüttlerMorbin 没关系。如果我发现任何有关披露的信息,那么我会在此处发布。 :)
【解决方案2】:

只需从 Attribute Inspector 或通过如下编码设置 UITableViewCell 的 tint 颜色

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellIdentifier = "SimpleTableViewCell"
    let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)

    // just add below lines
    cell.accessoryType = UITableViewCellAccessoryType.checkmark
    cell.tintColor = UIColor.red


    return cell
}

@HenriqueGüttlerMorbin 检查这个希望它对你有用。

【讨论】:

    【解决方案3】:

    您还可以在单​​元格类(UITableViewCell 类的子类)中设置颜色。如果您想为表格视图的所有行应用相同的颜色,请在 awakeFromNib 方法中设置 tintColor 属性。像这样:

    override func awakeFromNib() {
        super.awakeFromNib()
        accessoryType = .checkmark
        tintColor = .red
    }
    

    当然,如果你在视图控制器的 cellForRowAt 方法中设置颜色,你可以使用 indexPath 参数根据显示的行设置不同的颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-02
      • 2016-09-14
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      相关资源
      最近更新 更多