我知道这个问题已经被问过并回答了很多,但我似乎无法让它发挥作用。
我有一个带有全尺寸 WKWebView 的 UIViewController 。一切工作正常,除了状态栏在刘海设备上看起来不合适。
问题是,没有任何效果,即使是我自己来自其他应用程序的代码。
到目前为止我尝试过的事情(这在另一个应用程序中工作得很好......):
if #available(iOS 13, *)
{
let statusBar = UIView(frame: (UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.windowScene?.statusBarManager?.statusBarFrame)!)
//statusBar.backgroundColor = UIColor(red: 242/255, green: 242/255, blue: 242/255, alpha: 1.0)
statusBar.backgroundColor = UIColor.red
UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.addSubview(statusBar)
}
else
{
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor))
{
statusBar.backgroundColor = UIColor(red: 242/255, green: 242/255, blue: 242/255, alpha: 1.0)
}
}
和这个:
extension UIApplication {
var statusBarUIView: UIView? {
if #available(iOS 13.0, *) {
let tag = 3848245
let keyWindow: UIWindow? = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
if let statusBar = keyWindow?.viewWithTag(tag) {
return statusBar
} else {
let height = keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?? .zero
let statusBarView = UIView(frame: height)
statusBarView.tag = tag
statusBarView.layer.zPosition = 999999
keyWindow?.addSubview(statusBarView)
return statusBarView
}
} else {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
}
return nil
}
}
一切都来自这里:
如何更改iOS 13状态栏背景颜色和文字颜色? https://stackoverflow.com/questions/56651245/how-to-change-the-status-bar-background-color-and-text-color-on-ios-13
iOS 13 更改状态栏颜色? https://stackoverflow.com/questions/60519792/change-status-bar-color-in-ios-13
如何在 Swift 3 中设置状态栏样式 https://stackoverflow.com/questions/38740648/how-to-set-status-bar-style-in-swift-3
甚至尝试从 WKWebView 中显示的我的网页执行此操作:https://itnext.io/make-your-pwas-look-handsome-on-ios-fd8fdfcd5777 https://itnext.io/make-your-pwas-look-handsome-on-ios-fd8fdfcd5777
解决该问题的唯一解决方法是更改主视图的背景颜色。
问题是,这也会改变底部的颜色。
我什至尝试弄乱 info.plist 文件中的样式。
对我所缺少的有什么想法吗?