With the arrival of iOS 13 statusBar's view is no longer accessible trough:
value(forKey: "statusBar") as? UIView
Due to:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
But it's not clear how it should be used for changing colours as keyWindow?.windowScene?.statusBarManager
does not appear to contain anything related to it.
I'm compiling my code with (iOS 10, *) compatibility, so I intend to continue using UIKit.
Any ideas regarding this subject?
for swift 5.0 I've done this to change background color,
https://medium.com/@trivediniki94/surprises-after-upgrading-to-xcode-11-ios-13-b52b36e05fa8
Unfortunately Apple deprecated some of the mentioned methods of accessing the status bar and editing its attributes. You will have to use the The
StatusBarManager
object of theWindowScene
. The following method works for iOS 13 and above:Tested and 100% worked for me
remove status bar from the key window
in
viewDidLoad
andviewWillAppear
call above functionUse the following code:
to achieve this result:
you can try this
I do this, can get statusBar,but set statusBar backgroundColor do not work