Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem setTintColor doesn't work for dark colors

I am setting the tintColor of a UIBarButtonItem. This works as long as the color is a bright color, as soon as I try to set it to darkGrayColor nothing happens, in fact it changes the tint to white! But if I change the color to redColor then it works... What is going on here?

UIBarButtonItem *penButton = [_toolBar.items objectAtIndex:3];
UIBarButtonItem *crossButton = [_toolBar.items objectAtIndex:4];

//This actually sets the tint to white not gray, which is odd?
[penButton setTintColor:[UIColor darkGrayColor]]; 
[crossButton setTintColor:[UIColor redColor]]; //Red is fine, as is green etc
like image 520
Chris Avatar asked Jan 09 '12 23:01

Chris


1 Answers

The difference between [UIColor redColor] and [UIColor darkGrayColor] is that the former is set using RGB values and the latter with a grayscale, and the UIBarButtonItem is somehow ignoring the grayscale. You can test this theory by comparing:

[penButton setTintColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]]; 

[penButton setTintColor:[UIColor colorWithWhite:0.5 alpha:1.0]]; 

If the former is as expected but the latter is not, then the problem is indeed with grayscale. Otherwise I have no idea what's causing this behavior.

like image 66
PengOne Avatar answered Nov 03 '22 01:11

PengOne