IOS: unable to set hue color of navigation bar

Here is the n00b question, but I can't seem to allow reading my books and notes:

I am using a navigation control and I cannot understand why my code does not set the hue color for it.

In my application delegation implementation file under applicationDidFinishLaunching: ::

  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]; 

navController initializes only thin, but with black color.

+4
source share
4 answers

You see a black navigation bar because [UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1] black!

You do integer division, so 20/255 == 0 . Express these values ​​as floating, and you should see the color you want:

[UIColor colorWithRed:20.0/255 green:44.0/255 blue:86.0/255 alpha:1]

+11
source

This is black because you divide integers.

 [UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1]; 

Try the following:

 [UIColor colorWithRed:20.0f/255.0f green:44.0f/255.0f blue:86.0f/255.0f alpha:1.0f]; 
+3
source

(Most) hue colors only work on iOS 5.0+ (read the class link :))

+1
source

for ios 8.0

  self.navController.navigationBar.barTintColor = [UIColor colorWithRed:20/255 green:44/255 blue:86/255 alpha:1]; 
+1
source

Source: https://habr.com/ru/post/1403539/


All Articles