I am building an app for iOS13. I want to change the text color of status bar according to the color scheme which user can select. It seems the text color of status bar cannot be changed directly, so I try to change the statusBarStyle instead.
First I try:
var myStatusBarStyle = UIStatusBarStyle.default { didSet { setNeedsStatusBarAppearanceUpdate() } }
override var preferredStatusBarStyle : UIStatusBarStyle { return myStatusBarStyle; }
But it did not work.
Then I try:
UIApplication.shared.statusBarStyle = myStatusBarStyle;
It does do the job! But Xcode gives a warnning: " 'statusBarStyle' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene insted."
so, in sceneWillEnterForeground(_ scene: UIScene) I try:
guard let ws = (scene as? UIWindowScene) else { return }
if let t = ws.statusBarManager { print(t.statusBarStyle) }
Unfortunately, t.statusBarStyle is readonly.
Now, how can I do? ps: I have no Navigation Bar or Tab Bar in the Main.storyboard.
self.navigationController?.navigationBar.barStyle = .black
To make status bar black and it works
You can use various options instead of black as you like (.default , .blackTranslucent , .blackOpaque) in place of .black
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.