Mit iOS13 kann ich die Hintergrundfarbe der Statusleiste nicht mehr ändern, da auf die Statusleiste mit "Wert für Schlüssel" nicht mehr zugegriffen werden kann. Hat jemand herausgefunden, wie dies möglich ist, oder gibt es Kenntnisse darüber, dass dies in der endgültigen Version von iOS13 möglich sein wird?
Ich bin bereits auf verschiedene Vorschläge gestoßen, z. B. die Verwendung der UIApplications StatusBarView (in xcode 11, Beta 7 nicht mehr verfügbar) oder die Verwendung des Statusbarmanagers. Beide geben keinen Zugriff auf die Statusleiste.
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) {
statusBar.backgroundColor = <Some Color>
}
Ich erwarte, dass die Statusleiste die Hintergrundfarbe erhält, die ich benötige.
wenn Sie eine Navigationsleiste haben
self.navigationBar.barTintColor = UIColor.blue
or
UINavigationBar.appearance().barTintColor = UIColor.blue
wenn es keine Navigationsleiste gibt
view.backgroundColor = UIColor.blue
wenn Ihr Hintergrund eine Webansicht ist
webView.scrollView.backgroundColor = UIColor.blue
es fehlen wahrscheinlich noch mehr Fälle
Ich habe die zentrale ThemeManager-Klasse verwendet, in der ich alle UI-Farben festgelegt habe. So habe ich es gelöst. Sie können Teile der Lösung nehmen, die Ihren Anforderungen entsprechen:
let sharedApplication = UIApplication.shared
sharedApplication.delegate?.window??.tintColor = setYourColor
if #available(iOS 13.0, *) {
let statusBar = UIView(frame: (sharedApplication.delegate?.window??.windowScene?.statusBarManager?.statusBarFrame)!)
statusBar.backgroundColor = setYourColor
sharedApplication.delegate?.window??.addSubview(statusBar)
} else {
// Fallback on earlier versions
sharedApplication.statusBarView?.backgroundColor = setYourColor
}
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .blue
self.navigationController?.navigationBar.scrollEdgeAppearance = appearance
Ich hoffe, dies wird dir helfen.
Rufen Sie dies in Ihrem Basisansichts-Controller auf
public extension UIViewController {
func setStatusBar(color: UIColor) {
let tag = 12321
if let taggedView = self.view.viewWithTag(tag){
taggedView.removeFromSuperview()
}
let overView = UIView()
overView.frame = UIApplication.shared.statusBarFrame
overView.backgroundColor = color
overView.tag = tag
self.view.addSubview(overView)
}
}
Versuche dies
if #available(iOS 13.0, *) {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.backgroundColor = <insert your color here>
navigationBar.standardAppearance = navBarAppearance
navigationBar.scrollEdgeAppearance = navBarAppearance
}