how am I supposed to change this piece of code?
The current solutions for this problem either cover older iOS versions
or are unanswered.
This is the line:
UIApplication.shared.statusBarStyle = .lightContent
And I get those warnings:
'statusBarStyle' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene instead.
'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead
The code works, but would be nice to do not have those warnings popping up
3
Answers
You can override this property in your view controller :
Plus you can get the value of statusBarStyle like this:
but this is only get only property. In order to change the status bar style you can use the above code by overriding the ViewController property.
In case you want to change the status bar style of whole app then you can use info.plist like this:
Add "UIViewControllerBasedStatusBarAppearance" key and set its value to "false"
And then add "UIStatusBarStyleLightContent" key and set its value to "UIStatusBarStyle".
You can create a hosting controller by inheriting UIHostingController and then change the statusBarStyle like this:
And then you can set this hosting controller as your window root view controller in Scene Delegate like this:
I hope this will work for you and as of now I believe the only way is using HostingController.
if you want to remove the warning you can use:
This function works for me:
and you can use for all pages of app in "General" settings:
and in "info.plist"