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
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
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With