【问题标题】:how to change background color of the navigation bar and navigation text color如何更改导航栏的背景颜色和导航文本颜色
【发布时间】:2014-04-28 17:32:39
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios ios7 rubymotion


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-30
        • 2023-04-06
        • 2020-08-12
        • 2021-09-12
        • 1970-01-01
        • 1970-01-01
        • 2018-01-05
        • 1970-01-01
        相关资源
        最近更新 更多