How to get the status bar height in iOS 13?
As the warning hints, you can access the statusBarManager
which has a statusBarFrame
property. This is defined on your UIWindow
's windowScene
.
let height = view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
Status bar height in Swift
Is there any problems with Swift 2.x:
UIApplication.sharedApplication().statusBarFrame.size.height
Swift 3 or Swift 4:
UIApplication.shared.statusBarFrame.height
Make sure UIKit
is imported
import UIKit
In iOS 13, you will get a deprecated warning"
'statusBarFrame' was deprecated in iOS 13.0: Use the statusBarManager
property of the window scene instead.
To fix this:
let height = view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
iOS 13 setting status bar background color
Kuray just provided me a solution here:
https://freakycoder.com/ios-notes-13-how-to-change-status-bar-color-1431c185e845
Add the below to viewdidload. Please head over to his medium post and give him a few claps!
if #available(iOS 13.0, *) {
let app = UIApplication.shared
let statusBarHeight: CGFloat = app.statusBarFrame.size.height
let statusbarView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: statusBarHeight))
statusbarView.backgroundColor = UIColor.red
view.addSubview(statusbarView)
} else {
let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
statusBar?.backgroundColor = UIColor.red
}
iOS - Getting Status bar height & width 0 in landscape mode
We can achieve this by using
window.safeAreaLayoutGuide.layoutFrame
For Ex:
let safeFrame = window.safeAreaLayoutGuide.layoutFrame;
let safeFrameHeight = safeFrame.origin.y;
let safeFrameWidth = safeFrame.origin.x;
Related Topics
Fbsession: an Attempt Was Made Reauthorize Permissions on an Unopened Session
Populating Tableview with Multiple Sections and Multiple Dictionary in an Array in Swift
Load Image from Bundle with iOS
How to Turn Flashlight on and Off in Swift
Uiscrollview Adjusts Contentoffset When Contentsize Changes
Number of Threads Created by Gcd
To Convert Image to Cartoon in iOS
Mixing Static and Dynamic Sections in a Grouped Table View
How to Set the Title of a Navigation Bar Programmatically
How to Use Sf Symbols in iOS 12 and Below
Objective-C Delay Action with Blocks
How to Recycle Uitableviewcell Objects Created from a Xib
Reading Firebase Auth Error Thrown (Firebase 3.X and Swift)
How to Get Enum from Raw Value in Swift
How to Get iOS Appstorereceipturl into Base 64 Encoded String