Extra bottom space/padding on iPhone X?

Solution 1:

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)

Solution 2:

In Objective-C

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

Solution 3:

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

Now you can use bottomPadding as per your needs.

Solution 4:

If suddenly you have no view, for example, CollectionViewLayout, you can retrieve it from Window too:

private static var itemHeight: CGFloat {
    guard #available(iOS 11.0, *),
        let window = UIApplication.shared.keyWindow else {
            return Constants.itemHeight
    }
    return Constants.itemHeight - window.safeAreaInsets.bottom
}

Solution 5:

iOS 11 (a mix from answers above)

let padding = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0