Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS 13中更改状态栏颜色?_Ios_Swift - Fatal编程技术网

在iOS 13中更改状态栏颜色?

在iOS 13中更改状态栏颜色?,ios,swift,Ios,Swift,我一直在尝试更改状态栏的颜色,但使用按键状态栏时,我的应用程序正在崩溃。 我猜“状态栏”键在iOS 13中不可用 let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) { statusBar.backgroundColor = <Some

我一直在尝试更改状态栏的颜色,但使用按键状态栏时,我的应用程序正在崩溃。 我猜“状态栏”键在iOS 13中不可用

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) {
  statusBar.backgroundColor = <Some Color>
}
将statusBar:UIView=UIApplication.shared.value(forKey:“statusBar”)设为!UIView
if statusBar.responses(to:#选择器(setter:UIView.backgroundColor)){
statusBar.backgroundColor=
}

添加视图对我也不起作用。

1st-way

您可以像这样检查iOS版本并添加自定义状态栏->

覆盖函数视图显示(uu动画:Bool){
如果可用(iOS 13,*){
让statusBar=UIView(框架:(UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame)!)
statusBar.backgroundColor=.systemBackground
UIApplication.shared.keyWindow?.addSubview(状态栏)
}
}
第二条道路

您可以自定义UINavigationBarAppearance

if#可用(iOS 13.0,*){
让navBarAppearance=UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.titleTextAttributes=[.foregroundColor:UIColor.white]
navBarAppearance.largeTitleTextAttributes=[.foregroundColor:UIColor.white]
navBarAppearance.backgroundColor=
navigationBar.standardAppearance=导航栏外观
navigationBar.scrollEdgeAppearance=navBarAppearance
}

这是否回答了您的问题?请使用崩溃原因共享控制台日志。@DharmeshKheni发生此崩溃:**在-[UIApplication\u createStatusBarWithRequestedStyle:orientation:hidden:]中断言失败,***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UIApplication上调用了-statusBar或-statusBarWindow的应用程序:必须更改此代码,因为不再存在状态栏或状态栏窗口。改用窗口场景上的statusBarManager对象。”