Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Can't set navigation bar tint color

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.

like image 343
inorganik Avatar asked Dec 04 '22 17:12

inorganik


2 Answers

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]

like image 125
Jonah Avatar answered Dec 07 '22 05:12

Jonah


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];
like image 21
user1293953 Avatar answered Dec 07 '22 06:12

user1293953