Reputation: 2207
I'm using the following code in 'viewDidLoad' of the various view controllers of my tabbed app.
UIColor *tabBarColor = [UIColor colorWithRed:85.1 green:57.6 blue:71.4 alpha:.5];
[[UITabBar appearance] setTintColor:tabBarColor];
But the image that I get, which ought to be pink, is this:
I can make it lighter or darker by changing the alpha, but never colored--only black/white/gray.
Any thoughts about how I can solve this problem?
Upvotes: 1
Views: 556
Reputation: 5384
UIColor *tabBarColor = [UIColor colorWithRed:85.1 green:57.6 blue:71.4 alpha:.5]
Colors must come with decimal point after the number: 215.0/255. Because it's float.
try this:
UIColor *tabBarColor = [UIColor colorWithRed:(87/255.0) green:(153/255.0) blue:(165/255.0) alpha:1];
[[UITabBar appearance] setTintColor:tabBarColor];
Upvotes: 0
Reputation: 2921
Colors must come with decimal point after the number: 215.0/255
. Because it's float.
If you want to be precise with floats and doubles on 32bit and 64bit systems you also should add f after the number: 215.0f/255
. The compiler will know it's 32bit.
Now your problem is you didn't write the divide mark: N_OF_COLORS / TOTAL_COLORS.
Upvotes: 1
Reputation: 300
Under header files in .m write this line #define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
now where you are setting color put this code for pink color [[UITabBar appearance] setTintColor:RGB(255, 192, 203)];
that's all
Upvotes: 5
Reputation: 7333
Try this:
if ([tabBarController.tabBar respondsToSelector:@selector(setTintColor:)])
{
[tabBarController.tabBar setTintColor: tabBarColor];
}
Upvotes: 1