17

这是我的代码:

cell.accessoryType = UITableViewCellAccessoryType.Checkmark

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

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

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

4

3 回答 3

38

是的,你可以做到。

只需设置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 执行此操作

输出

于 2015-06-10T17:14:58.047 回答
11

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

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 检查这个希望它对你有用。

于 2017-01-10T07:16:38.923 回答
0

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

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

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

于 2019-09-01T16:31:09.933 回答