I am trying to get the status bar of my iOS (webView) app not Translucent.
I tried this inside func viewDidLoad():
self.navigationController?.navigationBar.isTranslucent = false
And this in the appDelegate:
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().backgroundColor = .white
This is what I am getting when scrolling the page..
You cannot change those properties for the status bar. You can only set, .default, .lightContent. But if you want you can probably place a view underneath of it, which is not translucent and has a background color. Something like this:
let statusBarFrame = UIApplication.shared.statusBarFrame
let statusBarView = UIView(frame: statusBarFrame)
self.view.addSubview(statusBarView)
statusBarView.backgroundColor = .green
That can go in you viewDidLoad()
method of the ViewController
Swift 5.1 iOS 13.0 Just in case for the current deprecations...
if #available(iOS 13.0, *) {
let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
let statusBarFrame = window?.windowScene?.statusBarManager?.statusBarFrame
let statusBarView = UIView(frame: statusBarFrame!)
self.view.addSubview(statusBarView)
statusBarView.backgroundColor = .green
} else {
//Below iOS13
let statusBarFrame = UIApplication.shared.statusBarFrame
let statusBarView = UIView(frame: statusBarFrame)
self.view.addSubview(statusBarView)
statusBarView.backgroundColor = .green
}
This fixed it for me when trying to slide a view from above into the screen, without seeing it on status bar while it animates:
view.clipsToBounds = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With