【发布时间】: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