2014-04-28 291 views
1

我希望导航栏的背景颜色为黑色,导航栏上的文本为白色。如何更改导航栏和导航文本颜色的背景颜色

一切看起来都对我的模拟器罚款,如下图所示:

enter image description here

然而,当我测试它的实际设备瓦特/ 7.1,即使导航栏的背景颜色为橙色,标题屏幕是黑色的。

这是我在我的应用程序委托我做:

@window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller) 
@window.rootViewController.navigationBar.barTintColor = '#DF533B'.to_color 
@window.rootViewController.navigationBar.translucent = true 
@window.rootViewController.navigationBar.tintColor = UIColor.whiteColor 
@window.rootViewController.navigationBar.setTitleTextAttributes({ 
    UITextAttributeTextColor => UIColor.whiteColor 
}) 

deployment_target7.0app.sdk_version7.1

我应该把我的所有控制器的viewDidLoad这个代码?

回答

0

不熟悉RubyMotion,但你应该使用UIAppearance代理:在您的AppDelegate加载主窗口之前,

[[UINavigationBar appearance] setBarTintColor:[self navBarColor]]; 

[[UINavigationBar appearance] setTintColor:[self navBarTitleColor]]; 

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [self navBarTitleColor], NSFontAttributeName : [self titleFont]}]; 

你应该这样做。

0

只要添加到Moby的答案看起来是正确的,请确保将它添加到您的应用程序委托的didFinishLaunchingWithOptions中。