Auf Art und Weise zu helfen, nahmen dies zu erreichen, ist eine UIView mit der richtigen Position und Dimension zu erstellen, es dann direkt an den UIWindow hinzufügen:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var statusBarColorView: UIView?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window?.makeKeyAndVisible()
let v = UIView(frame: CGRect(x: 0, y: 0, width: window?.frame.size.width ?? 1024, height: 20))
v.backgroundColor = UIColor.white
v.translatesAutoresizingMaskIntoConstraints = false
window?.addSubview(v)
window?.addConstraints(NSLayoutConstraint.constraints(
withVisualFormat: "V:|-0-[v(==20)]",
options: [],
metrics: nil,
views: ["v": v]))
window?.addConstraints(NSLayoutConstraint.constraints(
withVisualFormat: "H:|-0-[v]-0-|",
options: [],
metrics: nil,
views: ["v": v]))
return true
}
Das Problem bei diesem Ansatz besteht darin, dass Sie ihn entsprechend der Geräteausrichtung/des aktuell angezeigten View-Controllers ein- und ausblenden müssen.
ändern Farbe wird wie folgt aussehen:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.statusBarColorView?.backgroundColor = UIColor.blue
}
}
Sie werden sicherlich UIStatusBarStyle entsprechend Ihrer Farbe anpassen möchten, können Sie dies erreichen, indem YES
für den Schlüssel UIViewControllerBasedStatusBarAppearance
in Ihrem Info.plist Auswahl
Ja, es ist möglich –
siehe http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7 –
Ja, Sie können es einfach auf Ihrem root setzen Regler. – Sulthan