【问题标题】:Color of status bar does not change as my navigationbar状态栏的颜色不会改变为我的导航栏
【发布时间】:2018-03-02 21:18:38
【问题描述】:

我遇到了一个奇怪的问题。突然,我的状态栏的颜色与我的 tabbarcontroller 中的导航栏的颜色不同。

我试过设置导航栏的颜色

self.navigationController!.navigationBar.barTintColor = UIColor(red: 57, green: 79, blue: 116)
        self.navigationController?.navigationBar.tintColor = UIColor.white
        self.navigationController?.navigationBar.isTranslucent = false
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

但它只是改变导航栏的颜色,而不是状态栏。我错过了什么?

【问题讨论】:

  • 您确定没有在代码中的任何位置更改 navigationBar 高度吗?
  • 是的,我很确定
  • 仅供参考 - 您创建的 UIColor 不正确。值应在 0.0 - 1.0 范围内。

标签: ios swift uitabbarcontroller navigationbar


【解决方案1】:

在情节提要中创建导航控制器,将其绑定到控制器并更改那里的颜色。如果它当然允许你的项目..

【讨论】:

    【解决方案2】:

    Answer found here:

    extension UIApplication {
        var statusBarView: UIView? {
            return value(forKey: "statusBar") as? UIView
        }
    }
    
    UIApplication.shared.statusBarView?.backgroundColor = .red
    

    【讨论】:

    • 这是不必要的,并且可能会在未来的 iOS 更新中停止工作,或者让您的应用因挖掘私有子视图结构而被 Apple 拒绝。有无数应用程序不需要这样的代码来让状态栏显示正确的颜色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多