Reputation: 25525
Here is a n00b question, but one I can't seem to solve reading my books and notes:
I'm implementing a navigation control, and I can't figure out why my code is failing to set a tint color for it.
In my app delegate implementation file, under applicationDidFinishLaunching:
method:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController *rootView = [[rootViewController alloc] initWithNibName:@"rootViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:rootView];
self.navController.navigationBar.tintColor = [UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1];
The navController
initializes just fine but with a black color.
Upvotes: 4
Views: 3141
Reputation: 1167
for ios 8.0
self.navController.navigationBar.barTintColor = [UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1];
Upvotes: 1
Reputation: 33
This is black color, because you divide integers.
[UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1];
Try this:
[UIColor colorWithRed:20.0f/255.0f green:44.0f/255.0f blue:86.0f/255.0f alpha:1.0f];
Upvotes: 3
Reputation: 17958
You're seeing a black nav bar because [UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1]
is black!
You're performing integer division so 20/255 == 0
. Express those values as floats and you should see the color you expected:
[UIColor colorWithRed:20.0/255 green:44.0/255 blue:86.0/255 alpha:1]
Upvotes: 11
Reputation: 10303
(Most of )the tint colors only work on iOS 5.0+ (read the class reference:) )
Upvotes: 1