导航栏与视图相同的bg颜色

我们的devise师希望导航栏具有与视图相同的背景颜色。 不过,他们也希望导航栏保持半透明。

显然,如果我把它设置为非半透明的,它会起到一定的作用:

[[UINavigationBar appearance] setTranslucent:NO];

但这不是预期的效果。 有没有一种方法,我可以使他们相同的颜色,而无需花费数小时调整导航栏的背景颜色?

这就是我们将导航和视图设置为相同的颜色时的样子:

图片

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

只需设置背景和阴影的空白图像:

 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new]; self.navigationController.navigationBar.translucent = YES; 

使用此代码希望它的作品

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

我认为下面的代码将帮助你实现这一点。

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

您也可以使用RGB代码或hex的颜色。