0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ken
  • 1,155
  • 2
  • 19
  • 36
  • 1
    AFAIK, that value ignores safe areas, it's the real deal – LinusGeffarth May 28 '19 at 12:49
  • 2
    It's worth noting that `bounds` is the screen-rect measured in _points_, taking into account the orientation, whereas `nativeBounds` returns the actual display dimensions in _pixels_, without taking into account the orientation. – Alladinian May 28 '19 at 12:56
  • 1
    @Sh_Khan This doesn't look like a duplicate at all — the OP here already knows how to get the screen bounds (i.e. "resolution"), but is asking whether the returned rectangle represents the entire screen or just the safe area. The dupe you pointed to doesn't address that at all, being far older than the notion of a safe area. – Caleb May 28 '19 at 13:30

1 Answers1

2

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:

portion of display table

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:

part of a rectangle drawn at the screen bounds

Caleb
  • 124,013
  • 19
  • 183
  • 272