首页 文章

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

提问于
浏览
1

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

我的模拟器上的一切看起来都很好,如下所示:

enter image description here

但是,当我在实际设备w / 7.1上测试时,即使导航栏的背景颜色为橙色,屏幕 Headers 也是黑色 .

这就是我在我的应用程序委托中所做的事情:

@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 中吗?

2 回答

  • 0

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

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

    您应该在AppDelegate中加载主窗口之前执行此操作 .

  • 0

    只是为了添加Moby的答案,这对我来说是正确的,请确保将其添加到您的app委托的didFinishLaunchingWithOptions中 .

相关问题