【问题标题】:How to set statusBarStyle inside AppDelegate with no warnings如何在 AppDelegate 中设置 statusBarStyle 而没有警告
【发布时间】:2018-10-25 09:55:46
【问题描述】:

在我开始之前,如果这个问题被重复,我会道歉,因为我看到了很多问题,但我找不到我需要什么。

我想创建一个全局状态、导航、工具栏样式,如果可能的话,只从我的应用程序委托创建 iPhone X 上视图的底部,因此我不必从每个 Viewcontroller 设置它。

到目前为止,我有:

extension UIApplication {

    var statusBarView: UIView? {
        return value(forKey: "statusBar") as? UIView
    }

}

还有一个在 didFinishLaunchingWithOptions 方法中调用的函数

private func setupNavigationBarStyle(){

     UIApplication.shared.statusBarView!.backgroundColor = UIColor.AppColors.statusBar
     UIApplication.shared.statusBarStyle = .lightContent
     UINavigationBar.appearance().barTintColor = .brown
     UINavigationBar.appearance().tintColor = .green
     UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.yellow]
     UINavigationBar.appearance().isTranslucent = false

    }

我使用情节提要为我的视图控制器附加了一个虚拟设计

最后的结果是

尽管不是最好的设计,但我有 3 个问题。

  • UIApplication.shared.statusBarStyle = .lightContent 已弃用,它显示警告,我不希望这样。

  • 如何更改 iPhone X 以后的底部颜色(当前为红色,水平线所在的位置)。

  • 我能否将 statusBarStyle 更改为另一个未定义的样式并更改状态栏中的文本颜色 Purple?

【问题讨论】:

  • 我删除了 [xcode] 标签,因为您的问题与 xcode 无关。你只是在使用它
  • stackoverflow.com/questions/38740648/… 第一个。但底部栏的问题应该是关于另一个主题的。
  • 我看到了这个问题,但它没有按我的意愿工作。主要原因是当我的 UIViewController 未嵌入 UINavigationController 时,不会调用 preferredStatusBarStyle

标签: ios swift uinavigationbar uistatusbar


【解决方案1】:

希望对你有帮助

  • UIApplication.shared.statusBarStyle = .lightContent 已弃用,它显示警告,我不希望这样。

    转到项目 -> 目标,将状态栏样式设置为浅色

    • 如何更改 iPhone X 以后的底部颜色(当前为红色,水平线所在位置)。

    无法修改颜色,您不必担心,因为它不在您的控制范围内,并且保证可见。For Info(https://medium.freecodecamp.org/reverse-engineering-the-iphone-x-home-indicator-color-a4c112f84d34)。

    • 我可以为另一个未定义的状态栏样式更改状态栏样式并更改状态栏紫色中的文本颜色吗?

      func setStatusBarBackgroundColor(color: UIColor) {
      
          guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }
              statusBar.backgroundColor = color
      }
      
      //Use self.setStatusBarBackgroundColor(color: .purple)
      

谢谢

【讨论】:

    猜你喜欢
    • 2021-11-12
    • 1970-01-01
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 2019-04-22
    • 1970-01-01
    相关资源
    最近更新 更多