繁体   English   中英

如何更改导航栏的背景颜色和导航文本颜色

[英]how to change background color of the navigation bar and navigation text color

我希望导航栏的背景颜色为黑色,而导航栏上的文本为白色。

如下所示,在我的模拟器上一切正常:

在此处输入图片说明

但是,当我在带有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中?

不熟悉RubyMotion,但是您应该使用UIAppearance代理:

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

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

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

在将主窗口加载到AppDelegate中之前,应执行此操作。

只是要添加到对我来说似乎正确的Moby答案中,请确保将其添加到应用程序委托的didFinishLaunchingWithOptions中。

暂无
暂无

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

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