在视图控制器上,我想将状态栏的颜色设置为黑色,但我无法更改它。我为此目的使用下面的代码。
func setUpUI() {
self.navigationController?.setNavigationBarHidden(true, animated: false)
UIApplication.shared.statusBarStyle = UIStatusBarStyle.default
}
我还在info.plist中添加了值
您只需覆盖状态栏的返回值,如下所示:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Use below code for swift 4 and Xcode 9.2.
1)在
info.plist设置
查看基于控制器的状态栏外观键
没有
2)在
AppDelegate中
didFinishLaunchingWithOptions
设置低于代码
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
statusBar.backgroundColor = UIColor.red
}
UIApplication.shared.statusBarStyle = .lightContent