Extra bottom space/padding on iPhone X? Extra bottom space/padding on iPhone X? ios ios

Extra bottom space/padding on iPhone X?


In iOS 11, views have a safeAreaInsets property. If you get the bottom property of these insets you can get the height of the bottom padding while on iPhone X:

if #available(iOS 11.0, *) {    let bottomPadding = view.safeAreaInsets.bottom    // ...}

(likewise for the top padding with status bar)


In Objective-C

if (@available(iOS 11.0, *)) {   UIWindow *window = UIApplication.sharedApplication.keyWindow;   CGFloat bottomPadding = window.safeAreaInsets.bottom;}


var bottomPadding: CGFloat = 0.0if #available(iOS 11.0, *) {     let window = UIApplication.shared.keyWindow     bottomPadding = window?.safeAreaInsets.bottom ?? 0.0}

Now you can use bottomPadding as per your needs.