59

Could someone be so kind to show me how to change the color on the checkmark in UITableView?

I have searched but don't seem to get it to work.

Cheers

PeterK
  • 4,243
  • 4
  • 44
  • 74

15 Answers15

210

Since the iOS SDK has changed since the accepted answer, I thought I'd just update with a new answer.

You can in fact change the color of the checkmark in a UITableViewCell by adjusting the tintColor property of the UITableViewCell.

You can also set an appearance proxy for all UITableViewCells so that ALL instances have a specific tint color unless otherwise specified

[[UITableViewCell appearance] setTintColor:[UIColor redColor]];

Swift: In Swift change the tintcolor to the color you want to change the color of any Accessory Type

cell.tintColor = .black
nvrtd frst
  • 6,272
  • 4
  • 28
  • 34
  • Yes Anastasia, the property tintColor is available for UIView in iOS 7.0 and later. – Donnit Oct 11 '13 at 17:23
  • 2
    Wonder why they don't set the accessory view when we set the accessory type so we can customize it instead of going for hacks like setting the tint color for the entire cell or table just so the checkmark color changes. – trss Jan 16 '14 at 11:05
  • This does not seem to work any more in iOS 9.3, unless I am missing something. Can anyone confirm? – user3352495 Aug 25 '16 at 21:35
  • It works in 10.1, you can also set it in Interface Builder. – Yusuf X Nov 22 '16 at 21:09
  • Note that, if you've used the UIAppearance protocol to set UIControl's `tintColor`, the checkmark accessory type will inherit that color instead of UITableViewCell's `tintColor`. You may need to do something like this to override it: `UIControl.appearance(whenContainedInInstancesOf: [CustomTableViewCell.self]).tintColor = .white` – jamesk Mar 10 '17 at 00:15
41

Apple doesn't provide a public way to change the color of the checkmark so you'll have to do it with an image.

This is very simple, just set the accesoryView property of the cell to a UIImageView containing a checkmark of the correct color.

It'll look like this:

UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coloredCheckmark.png"]];
cell.accessoryView = checkmark;
[checkmark release];

Enjoy!

Andrew Zimmer
  • 3,183
  • 1
  • 19
  • 18
35

If you are looking for a Swift version:

Directly on the cell

For example in tableView(_:,cellForRowAtIndexPath:)

cell.tintColor = UIColor.redColor()

Using the appearance protocol

UITableViewCell.appearance().tintColor = UIColor.redColor()
mokagio
  • 16,391
  • 3
  • 51
  • 58
29

The following worked for me in iOS 7.

[self.tableView setTintColor:[UIColor someColor]];
Niall C.
  • 10,878
  • 7
  • 69
  • 61
Vinicius Souza
  • 447
  • 4
  • 7
15

This image shows how to do this in storyboards.The Tint color is the checkmark color.

enter image description here

kalan nawarathne
  • 1,944
  • 27
  • 26
14

I found that igraczech's answer is mostly correct, but with iOS 6 or later, you can just set the tint color of the entire tableview and default items will inherit down.

[self.tableView setTintColor:[UIColor someColor]];

This worked for me and allowed me to color in the checkmark.

Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
8

Starting iOS 7 you could set the tint color of your view controller's view so that this tint colow will be propageted to all it's child views. So to set your UITableViewCell's checkmark as purple color (for example), in your viewWillAppear method you need to:

[self.view setTintColor:[UIColor purpleColor]];
Raunak
  • 3,314
  • 1
  • 22
  • 28
3

The UIAccessoryTypeCheckmark (right side) inherits background color of its tableview.

self.tableView.backgroundColor = [UIColor clearColor];
igraczech
  • 2,408
  • 3
  • 25
  • 30
3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
HNCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HNCustomTableViewCell" forIndexPath:indexPath];
cell.tintColor = [UIColor colorWithRed:0.99 green:0.74 blue:0.10 alpha:1.0];
return cell;
}

It work for me.

josliber
  • 43,891
  • 12
  • 98
  • 133
Antony Wong
  • 562
  • 5
  • 17
3
 UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath];
cell.tintColor=UIColor.whiteColor;
return cell;
  • 1
    Can you please provide some more commentary as to what this block of code does? – Deanna Apr 10 '18 at 14:51
  • 1
    Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others. – Neuron Apr 10 '18 at 15:34
  • @Deanna When a UITableViewCell is selected, the OS goes through the view hierarchy and changes the backgroundColor of tableView to selected colour – Raviteja Mathangi Jun 24 '19 at 13:21
  • @Raviteja_DevObal can you update the answer? It was flagged as low quality as it was just a snippet of code with no explanation. – Deanna Jun 24 '19 at 13:33
2
#import "UIImage+Color.h"

UIImage *image = [[UIImage imageNamed:@"ic_check_black_24dp.png"] changeColor:CLR_BUY];
UIImageView *checkmark = [[UIImageView alloc] initWithImage:image];
cell.accessoryView = checkmark;
Gank
  • 4,507
  • 4
  • 49
  • 45
2

I always used this easy way:

UITableViewCell *cell = ...;
cell.tintColor = [UIColor greenColor];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
Bogdan Evsenev
  • 851
  • 9
  • 16
1

You don't have to use your own image, you can simply change it in your view did load with the following code.

[self.tableView setTintColor:[UIColor colorWithRed:250/255.0 green:223/255.0 blue:6/255.0 alpha:1]]

Cheers!

TheRealRonDez
  • 2,807
  • 2
  • 30
  • 40
1

Swift 3.1, iOS 9+

if #available(iOS 9.0, *) {
            UIImageView.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).tintColor = UIColor.themeTint //add your color here 
        } else {
            // Fallback on earlier versions
        }

Result

Nitesh Borad
  • 4,583
  • 36
  • 51
1

The above answers are all great. But if you want to do it globally, just do

UITableViewCell.appearance().tintColor = .green

Nice little trick :)