2

iPhone XR screen resolution according to screenshots, apple website and etc.:

828x1792

iPhone XR screen resolution according to Swift:

375x812 (or 750x1624)

Why and how to deal with it?!

NOTE: all iphones Xx work properly except of this one - iphone XR (+iphone XR simulator)

Vyachaslav Gerchicov
  • 2,317
  • 3
  • 23
  • 49

4 Answers4

4

There are two different concepts: UIKit size and Native resolution.

UIKit size is represented by points and is used when you're positioning views inside your project. Let's say your screen is has size 414x896 points, and you center your view to position [207,448], your view will be in the center of the screen.

Native resolution is represented by pixels and it's telling how much pixels screen of the device has. You can get native resolution of device by multiplying UIKit size with Native Scale factor which is individual for each device.

I created table for these sizes, sclae factors and resolution for all iPhones which supports iOS 12

iPhone       | UIKit size (points) | Native resolution (pixels) | Native Scale factor
-------------|---------------------|----------------------------|--------------------
Xs Max       | 414x896             | 1242x2688                  | 3
X, Xs        | 375x812             | 1125x2436                  | 3
Xr           | 414x896             | 828x1792                   | 2
6+,6s+,7+,8+ | 414x736             | 1080x1920                  | 2.608
6,6s,7,8     | 375x667             | 750x1334                   | 2
5s,SE        | 320x568             | 640x1136                   | 2

... from this table you can see that your iPhone Xr has UIKit size 414x896, not 375x812 as your wrote in your question.

You can get device's UIKit size by getting screen's bounds

UIScreen.main.bounds

and native resolution by getting native bounds

UIScreen.main.nativeBounds

... each of these works well for iPhone Xr so check once again if you're running your code on iPhone Xr and not on iPhone Xs/X which has UIKit size 375x812. Also this 750x1624 is just some weird scale of Xr' native resolution, so check if you're not doing any extra math.

Robert Dresler
  • 10,580
  • 2
  • 22
  • 40
  • man I have the same result using `nativeBounds`! Even according to your table `native resolution = UIKit size * native scale`. In reality it seems both XR simulator and real device work as X/XS but with scale factor == 2. – Vyachaslav Gerchicov Jan 14 '19 at 08:47
  • @VyachaslavGerchicov are you sure that you running your code on xr and not on xs? Look to last paragraph of my answer – Robert Dresler Jan 14 '19 at 08:53
3

This is because 'Display Zoom' is enabled on your iPhone XR.

Settings -> Display & Brightness -> Display Zoom -> Set to Standard

Elletlar
  • 3,136
  • 7
  • 32
  • 38
Coice
  • 31
  • 2
  • This is the right answer on this question and should be accepted as one. I currently also verified that with real iPhone XR device and 'Display Zoom' is the factor here.. – Mr.SwiftOak Nov 08 '21 at 13:01
2

There is a difference between the physical screen size and the UIKit size (pixels vs points).

UIKit uses points, a point can comprise of multiple pixels (this is where @2x, @3x) comes in.

The main difference between the XR versus the other X devices is that the XR uses @2x and the other devices are @3x.

Here are Apple's docs on this: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html

PaintCode have also made a really handy graphic to illustrate this:

https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

EDIT to answer rmaddy's comment.

If the storyboard is setup to show iPhone X then that's the size that will be returned until the views have been laid out.

Swinny89
  • 7,273
  • 3
  • 32
  • 52
0

You are getting the iphone X resolution, and that happens most probably because you are using the iphone X in storyboard. The code gives you the storyboard resolution first. If you want to get the real size, call layoutIfNeeded() method before the code that uses the resolution

fosfo09
  • 70
  • 4
  • `UIScreen.main.bounds` should get the rect with size which is not changed on the same device during time. Even on rotation width and height are swapped around but the pair of their values is not changed – Vyachaslav Gerchicov Jan 14 '19 at 09:19
  • yep UIScreen.main.bounds should get the right size always but it is not a good practice to use it. You can use it in complex situations, when you can't get the size of screen in any other way – fosfo09 Jan 15 '19 at 11:55
  • man I know it but the problem I describe is all these methods return `size x scale` but device has resolution `size2 x scale` and `size <> size2` – Vyachaslav Gerchicov Jan 17 '19 at 08:39