这是我的代码:
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
但是当我运行应用程序时,我看不到复选标记。
然后我将背景颜色设置为黑色,我可以看到一个白色的复选标记。
如何将复选标记的颜色更改为蓝色等其他颜色?
这是我的代码:
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
但是当我运行应用程序时,我看不到复选标记。
然后我将背景颜色设置为黑色,我可以看到一个白色的复选标记。
如何将复选标记的颜色更改为蓝色等其他颜色?
是的,你可以做到。
只需设置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 执行此操作
只需从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 检查这个希望它对你有用。
您还可以在单元格类(UITableViewCell 类的子类)中设置颜色。如果您想为表格视图的所有行应用相同的颜色,请在 awakeFromNib 方法中设置 tintColor 属性。像这样:
override func awakeFromNib() {
super.awakeFromNib()
accessoryType = .checkmark
tintColor = .red
}
当然,如果您在视图控制器的 cellForRowAt 方法中设置颜色,您可以使用 indexPath 参数根据显示的行设置不同的颜色。