简体   繁体   English

导航栏的背景颜色与视图相同

[英]Navigation bar same bg color as view

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: 这是我们将导航和视图设置为相同颜色时的样子:

图片

Try this code    

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

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;

Use this code hope it works 使用此代码希望它能工作

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

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. 您还可以使用RGB代码或十六进制中的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM