Reputation: 4699
I am trying to change the color of the navigation bars in my app with UIAppearance.
But only when I use a system color, it works:
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
[navigationBarAppearance setBarTintColor:[[UIColor alloc] initWithRed:220.0f green:47.0f blue:40.0f alpha:100.0f]]; // does not work
[navigationBarAppearance setBarTintColor:[UIColor colorWithRed:220.0f green:47.0f blue:40.0f alpha:100.0f]]; // does not work
[navigationBarAppearance setBarTintColor:[UIColor redColor]]; // works
Any suggestions?
Upvotes: 2
Views: 72
Reputation: 6275
The method
colorWithRed:green:blue:alpha:
accept four value between 0.0
and 1.0
. So if you have the components from 0.0
to 255.0
you need to normalize with a division by 255.0f
.
[UIColor alloc] initWithRed:220.0f/255.0f green:47.0f/255.0f blue:40.0f/255.0f alpha:100.0f/255.0f]
Upvotes: 1
Reputation: 4005
I think you are doing wrong with custom color method, its like this
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:127.0f/255.0f green:127.0f/255.0f blue:127.0f/255.0f alpha:1.0f]];
Upvotes: 1