2

Apple say this:

barTintColor

This color is made translucent by default unless you set the translucent property to NO.

So why is my code producing an opaque navigation bar?

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0/255.0f     green:119/255.0f blue:255/255.0f alpha:1.0f];

I tried adding this just in case, but no luck.

self.navigationController.navigationBar.translucent = YES;

Thanks

Community
  • 1
  • 1
Nathan
  • 155
  • 1
  • 2
  • 5

3 Answers3

2

Instead of this

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0/255.0f     green:119/255.0f blue:255/255.0f alpha:1.0f];

why don't you try setting the background color

self.navigationController.navigationBar.backgroundColor = [UIColor colorWithRed:0/255.0f     green:119/255.0f blue:255/255.0f alpha:1.0f];

The bar is translucent :)

As per your need. This will give a solid color to the navigation bar

NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[ver objectAtIndex:0] intValue] >= 7) {
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = NO;
}else {
self.navigationController.navigationBar.tintColor = [UIColor redColor];
}
Harsh
  • 2,852
  • 1
  • 13
  • 27
  • Thanks, but the colour then goes way, way too pale. I can't get it as dark as if I manually dragged in a navigation bar and chose a colour, with translucent checked. This doesn't seem right at all. – Nathan Mar 13 '14 at 20:35
  • You can change the alpha value and get the desired result! – Harsh Mar 13 '14 at 20:38
  • A translucent NavigationBar does not have full and deep colors.. If the background color of the ViewController is white, the NavigationBar will appear brighter. – filou Mar 13 '14 at 20:41
  • Anything above 1.0 makes no difference. Sorry I feel like I must be missing something really obvious, but it just doesn't work. filou: If I drag in a navigation bar and give it a tint, the colour is far darker than with this code. – Nathan Mar 13 '14 at 20:45
  • can you explain exactly what you want to achieve? i.e. what is you background colour and what do you want your navigation bar to have? – Harsh Mar 13 '14 at 20:46
  • The navigation bar will have text scrolling beneath it, but I want it to be blue in colour. – Nathan Mar 13 '14 at 20:50
  • Edited the post as per your need. Now you are able to have a solid color and a translucent color. There should not be a problem with this – Harsh Mar 13 '14 at 21:01
0

Its much easier to use the "appearance" proxy in your appDelagate.m. In your didGinishLaunchingWithOptions method include:

[UINavigationBar appearance].translucent = NO;
0

Swift 4

  navigationController!.navigationBar.isTranslucent = false;
barrylachapelle
  • 967
  • 4
  • 13
  • 34