How to find out the distance from the bottom safe area edge to the bottom of the screen?

Evgenii picture Evgenii · Nov 19, 2017 · Viewed 7.8k times · Source

I need to calculate the distance between the bottom anchor of the safe area and the bottom of the screen. Is there a way to do that in code given a view?

enter image description here

Answer

user6788419 picture user6788419 · Nov 20, 2017

Try this one

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