我正在创建一个iPhone应用程序,但是我的每个视图中导航栏的颜色不同?
我正在使用iOS7和Xcode 5进行开发。
我尝试编写以下代码在AppDelegate.m文件中使导航栏颜色相同:
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
What should I be doing?
我正在创建一个iPhone应用程序,但是我的每个视图中导航栏的颜色不同?
我正在使用iOS7和Xcode 5进行开发。
我尝试编写以下代码在AppDelegate.m文件中使导航栏颜色相同:
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
What should I be doing?
导航栏样式为半透明亮色(默认)或半透明暗色。默认情况下,translucent属性为YES,将其设置为NO并使用navigationbar的barTintColor属性设置导航栏背景颜色。
Objective-C
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
Swift 3
navigationController?.navigationBar.barTintColor = UIColor.white
navigationController?.navigationBar.isTranslucent = false
您需要设置barTintColor属性。
您可以使用Tint(barTintColor)字段指定自定义导航栏背景的色调颜色。默认背景色调颜色为白色。
如果您想要一个实心颜色,还可以将属性从顶部栏设置为不透明而不是半透明。 来自iOS7文档:https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UINavigationBar.html#//apple_ref/doc/uid/TP40012857-UINavigationBar-SW1