Joseph
Joseph

Reputation: 9351

UITableView change color of multiple selection checkmarks

how can I change the tint color of the multiple selection checkmark?

I tried [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method.

But it had no effect.

Am I restricted to the colors defined in the documentation of UITableViewCellSelectionStyle so blue and gray?

Thanks

Upvotes: 4

Views: 2126

Answers (2)

Chetan9007
Chetan9007

Reputation: 908

Swift 3.0

Just set the cell tint color in cellForRowAtindexPath for checkmark

cell.tintColor = UIColor.yourColor

and to change selection color set

let cellBackgroundColorView = uiview()

cellBackgroundColorView.backgroundColor = UIColor.yourColor

cell.selectedBackgroundView = cellBackgroundColorView

Upvotes: 4

BHASKAR
BHASKAR

Reputation: 1201

Note that in iOS 7, using

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];

will not work as expected, because in iOS 7 this is now gray, even if you pass the constant above. See:

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/c/tdef/UITableViewCellSelectionStyle

So use this to change color in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method.

UIView *cellBg = [[UIView alloc] init];
cellBg.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0)     alpha:1.0]; // this RGB value for blue color
cellBg.layer.masksToBounds = YES;
Cell.selectedBackgroundView = cellBg;

Upvotes: 3

Related Questions