Is this possible? I want the number of inches, not the number of pixels. I know it is approximately 160 ppi. But not exactly.
-
4You may be aware of this, but basing your code on the physical characteristics of the device may well cause issues in the future. If the next iPhone has a slightly bigger screen but keeps the same resolution (as some rumors have suggested) you code will be broken on that device. – Snips Nov 24 '11 at 14:06
-
There's a way to [get the screen size on OS X](http://stackoverflow.com/a/12589799/1993600), I wonder if it'll work on iOS? – adib Oct 21 '15 at 06:49
-
@adib It's been a while since you commented, but CGDisplayScreenSize is available only on macOS, sadly – Dave Nottage Apr 27 '20 at 05:35
11 Answers
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.

- 16,959
- 6
- 53
- 76
If it were available it would be in UIScreen or UIDevice but it is not there.
You can infer it from info in Erica's UIDevice-extension and the specs for each device listed here on Wikipedia.

- 75,956
- 16
- 112
- 147
Here's a short method that estimates the device screen size. It's updated as to the latest devices, but may fail on future ones (as all methods of guessing might). It will also get confused if the device is being mirrored (returns the device's screen size, not the mirrored screen size)
#define SCREEN_SIZE_IPHONE_CLASSIC 3.5
#define SCREEN_SIZE_IPHONE_TALL 4.0
#define SCREEN_SIZE_IPAD_CLASSIC 9.7
+ (CGFloat)screenPhysicalSize
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height < 500)
return SCREEN_SIZE_IPHONE_CLASSIC; // iPhone 4S / 4th Gen iPod Touch or earlier
else
return SCREEN_SIZE_IPHONE_TALL; // iPhone 5
}
else
{
return SCREEN_SIZE_IPAD_CLASSIC; // iPad
}
}

- 2,655
- 28
- 32
-
Of course, the introduction of the iPad Mini breaks this code (it's physical size is smaller than the iPad 2, but the same resolution). This can be a guide, but not a guarantee.. – Jeff Hay Jan 03 '13 at 16:47
-
1Nowadays you have iPhone 6 and 6+, which the user can run in "Zoom" mode, so the same phone can report different values for the bounds. – gnasher729 Mar 01 '16 at 15:28
You might need use [UIScreen mainScreen].scale;
CGFloat scale = [UIScreen mainScreen].scale;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat physicalWidth = screenRect.size.width * scale;
CGFloat physicalHeight = screenRect.size.height * scale;

- 2,796
- 2
- 27
- 32
-
That's not correct for iPhone 8 Plus according the [this guide](https://www.ios-resolution.com/). It's logical screen size: 414x736 and it has @3x scale screen, according to your answer it must has physical size 1242x2207 but it has 1080x1920 actually. – woheras Mar 31 '22 at 18:48
Maybe Jeff Hay's code can be adapted to include iPad Mini. The trick is to get the device's model identifier. The most recent non-retina iPad is "iPad2,4" and the first iPad mini is "iPad2,5". Now all you need to check is if the screen scaling is 1.0 (non-retina)
Although this code is not future-proof, you can always add more rules for model identifiers.
#import <sys/utsname.h>
#define SCREEN_SIZE_IPAD_MINI 7.9
struct utsname systemInfo;
uname(&systemInfo);
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && strcasecmp(systemInfo.machine, "iPad2,5") >= 0 [[UIScreen mainScreen] scale] == 1.0)
return SCREEN_SIZE_IPAD_MINI

- 213
- 1
- 7
The "formula" I use is
#define IS_iPhone5 ( fabs( (double)[ [ UIScreen mainScreen ] bounds ].size.height - (double)568 ) < DBL_EPSILON )

- 14,610
- 7
- 35
- 43

- 45
- 6
note: screen rotation matters here
extension UIScreen {
var physicalSize:CGSize {
return CGSize(width: bounds.width*scale, height: bounds.height*scale)
}
}
using:
print(UIScreen.main.physicalSize)

- 4,671
- 1
- 17
- 9
Since this question has been asked, I’ve created an open-source library to handle this problem: IRLSize. It can be used in either direction: to measure the size of a view (or the whole screen) in real-world dimensions, or to set the size of a view to a specific real-world dimension.

- 19,021
- 6
- 70
- 80
-
He may have considered this part of his research. At least help point him in the right direction. – eddieroger May 13 '14 at 13:52
-
2@eddieroger This is a two-and-a-half-year-old comment. Come on, man. – Jeff Kelley May 14 '14 at 18:00
Here is a Swift way to get screen sizes:
var screenWidth: CGFloat {
if UIInterfaceOrientationIsPortrait(screenOrientation) {
return UIScreen.mainScreen().bounds.size.width
} else {
return UIScreen.mainScreen().bounds.size.height
}
}
var screenHeight: CGFloat {
if UIInterfaceOrientationIsPortrait(screenOrientation) {
return UIScreen.mainScreen().bounds.size.height
} else {
return UIScreen.mainScreen().bounds.size.width
}
}
var screenOrientation: UIInterfaceOrientation {
return UIApplication.sharedApplication().statusBarOrientation
}
These are included as a standard function in:

- 38,543
- 21
- 161
- 168
-
This doesn't answer his question as he specifically says "I want the number of inches, not the number of pixels." – John Stephen Nov 02 '16 at 22:19
-
None of the answers do in that case. But at least we know how many inches an iphone is so its easy to calculate from here – Esqarrouth Nov 03 '16 at 07:27
Nobody said about fixedCoordinateSpace
. In Swift 3 to get the screen dimensions in a portrait-up orientation you should use: UIScreen.main.fixedCoordinateSpace.bounds

- 2,283
- 21
- 27
CGFloat scale = [UIScreen mainScreen].scale;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width * (scale/100.0f);
CGFloat screenHeight = screenRect.size.height * (scale/100.0f);
- scale is persent!

- 67
- 8