I have a relatively simple question but I can't seem to find the answer anywhere. When I use:
UIScreen.main.bounds.height
Does this give me the height from the bottom edge of the screen all the way to the top or only till the safe area? For eg. is the height only until the notch for the iPhone X or does it go all that way up past the notch.
is the height only until the notch for the iPhone X or does it go all that way up past the notch
You can easily check this yourself. Set a breakpoint somewhere in any iOS project, and see what rectangles are returned by bounds
or nativeBounds
for the main screen when the app runs on the device you're interested in, e.g. iPhone X:
(lldb) po [[UIScreen mainScreen] bounds]
(origin = (x = 0, y = 0), size = (width = 375, height = 812))
(lldb) po [[UIScreen mainScreen] nativeBounds]
(origin = (x = 0, y = 0), size = (width = 1125, height = 2436))
You can check that against the dimensions reported for the screen in Apple's documentation:
I'd assume from that that the rectangle returned by bounds
for the main screen represents the entire screen, not just the safe area. But if you're still not convinced, you could write a few lines of code that draws a rectangle with those dimensions, and you'll see that the notch and corners occlude parts of the rectangle: