How to change UITableViewCellAccessoryType.Checkmark's color?

14k Views Asked by At

Here's my code:

cell.accessoryType = UITableViewCellAccessoryType.Checkmark

But when I run the app, I can't see the checkmark.

Then I set background color to black, and I can see a white checkmark.

How to change checkmark's color to other colors like blue?

3

There are 3 best solutions below

2
On BEST ANSWER

Yes you can do it.

Just set the tintColor of cell.

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

Swift 3

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

OUTPUT

You can also do it from Attributes Inspector

OUTPUT

0
On

Just set the tint color of UITableViewCell from Attribute Inspector or by coding like below

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 check this hope it will work for you.

0
On

You can also set the colour in your cell class (the one subclassing the UITableViewCell class). Set the tintColor property in your awakeFromNib method if you want the same colour to be applied for all the rows of your table view. Like so:

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

Of course, if you set the colour in the cellForRowAt method of your view controller, you can use the indexPath parameter in your favour to set different colours according to the row displayed.