iOS get physical screen size programmatically?

William Jockusch picture William Jockusch · Nov 24, 2011 · Viewed 41.5k times · Source

Is this possible? I want the number of inches, not the number of pixels. I know it is approximately 160 ppi. But not exactly.

Answer

occulus picture occulus · Nov 24, 2011

There isn't an API that will give you this. Your best bet is to look at the device's screen size (in points) and from that surmise if it's an iPad or iPhone etc., and then use hard-coded values for the screen sizes.

Here's some code to get the screen size:

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

Be aware that width and height might be swapped, depending on device orientation.