PipEvangelist
PipEvangelist

Reputation: 631

How to change UITableViewCellAccessoryType.Checkmark's color?

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?

Upvotes: 20

Views: 14071

Answers (3)

Bruno Campos
Bruno Campos

Reputation: 403

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.

Upvotes: 0

Mahesh Kumar
Mahesh Kumar

Reputation: 1104

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.

Upvotes: 11

Ashish Kakkad
Ashish Kakkad

Reputation: 23882

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

Upvotes: 40

Related Questions