Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS get physical screen size programmatically?

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

like image 509
William Jockusch Avatar asked Nov 24 '11 13:11

William Jockusch


2 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.

like image 124
occulus Avatar answered Sep 28 '22 01:09

occulus


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.

like image 24
progrmr Avatar answered Sep 28 '22 00:09

progrmr