I was changing the background color of the status bar.
I tried to use the following code but I get warnings in Xcode 14 as my app support iOS 15 and above.
func setupStatusBar() {
if let statusBarFrame = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame {
let statusBarView = UIView(frame: statusBarFrame)
statusBarView.backgroundColor = UIColor.yellow
UIApplication.shared.windows.first?.addSubview(statusBarView)
}
}
App-level
You can change the status bar background color for all view controllers in your app by setting the UIStatusBarStyle property in the AppDelegate.swift file. The following code shows how to do this:
View controller-level
You can also change the status bar background color for a specific view controller by overriding the preferredStatusBarStyle property. The following code shows how to do this:
Note that the preferredStatusBarStyle property is deprecated in iOS 15. However, it is still supported for backward compatibility.
Here is an example of how to change the background color of the status bar in a SwiftUI view:
The statusBarBackground() modifier is a SwiftUI modifier that applies the background color of the view to the status bar.