问题
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:
回答1:
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;
回答2:
Try this code
[self.navigationController.navigationBar setBarTintColor:[UIColor backgroundcolor]];
[self.navigationController.navigationBar setTranslucent:NO];
回答3:
Use this code hope it works
[self.navigationController.navigationBar setBarTintColor:self.view.backgroundColor];
[self.navigationController.navigationBar setTranslucent:NO];
回答4:
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.
来源:https://stackoverflow.com/questions/28560220/navigation-bar-same-bg-color-as-view