1
votes

Our designer wants the navigation bar to have the same background color as the view's. However, they also want the navigation bar to remain translucent.

Obviously if I set it to non-translucent it works a treat:

[[UINavigationBar appearance] setTranslucent:NO];

But that is not the desired effect. Is there a way I can make them the same color without spending hours tweaking the background color of the navigation bar?

This is what it looks like when we set the navigation and view to the same color:

image

4
am i missing something here? can you not set the colour to [UIColor clearColor] ??Simon McLoughlin
why? it needs to be transparent and the same colour .... whats the difference?Simon McLoughlin
It still seems to ends up as a darker color due to the translucency.cjhill
Nope, we do not want a transparent navigation bar.cjhill

4 Answers

2
votes

Just set empty image for background and shadow:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
0
votes
Try this code    

 [self.navigationController.navigationBar setBarTintColor:[UIColor backgroundcolor]];
    [self.navigationController.navigationBar setTranslucent:NO];
0
votes

Use this code hope it works

[self.navigationController.navigationBar setBarTintColor:self.view.backgroundColor];
[self.navigationController.navigationBar setTranslucent:NO];
-1
votes

I thinks the following piece of code would help you to achieve this.

[[UINavigationBar appearance]setBarTintColor:[UIColor colorWithRed:0.04 green:0.38 blue:0.95 alpha:1.0]];

     [[UINavigationBar appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [[UIBarButtonItem appearance]setTintColor:[UIColor colorWithRed:1.00 green:1.00 blue:1.00 alpha:1.0]];

    [[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];

you can also use color from RGB code or from hex.