Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCellAccessoryType Change checkmark colour

I am trying to figure out how to programmatically(not in storyboard) set the colour for UITableViewCellAccessoryType.Checkmark.

I feel kinda stupid asking how to do something as simple as this, but I could not find the answer in the apple docs. Any help would be great. Thanks.

I set the accessory type like this:(works fine)

        cell.accessoryType = .Checkmark

EDIT : If you want to change the image used for checkmark, this worked for me. But POB's answer is what I ended up using to simply change the colour.

    let checkImage = UIImage(named: "checkmark.png")
    let checkmark = UIImageView(image: checkImage)

    cell.accessoryView = checkmark
like image 959
the_pantless_coder Avatar asked Sep 25 '14 18:09

the_pantless_coder


2 Answers

Here is code for Swift 3.0

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

    cell.tintColor = UIColor.red
    cell.accessoryType = .checkmark

    return cell
}
like image 64
Castor Avatar answered Nov 02 '22 04:11

Castor


The following code should work:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

    //Change cell's tint color
    cell.tintColor = UIColor.redColor()

    //Set UITableViewCellAccessoryType.Checkmark here if necessary
    cell.accessoryType = .Checkmark

    /* ... */

    return cell
}
like image 34
Imanou Petit Avatar answered Nov 02 '22 05:11

Imanou Petit