8

I'm really confused as to how iOS Ruler apps currently on the market are compatible with different size devices. An example is shown at the bottom.

After researching, I had come to the conclusion that getting the PPI of the current screen in realtime was impossible, which makes it impossible to programmatically draw a ruler.

My query is how do these ruler apps accurately display a ruler without being able to get the device PPI?

My first thought would be that the PPI and screen size for each device is hard-coded into the app. This seems like a lot of effort and a recipe for a million mistakes. Is this really how they have to do it? It would need to be tested on each different device to ensure it works correctly. I only have access to my iPhone 5S. Might they have different images of rulers for each different device? This would take up a lot of space on the phone.

I've seen similar questions on SO about drawing rulers, but (correct me if I'm wrong) they don't seem to have a solution for maintaining accuracy for different screen sizes and PPI. They all seem to say "it's impossible". If it's impossible, how is it done?

example

Neeku
  • 3,646
  • 8
  • 33
  • 43
Invalid Memory
  • 717
  • 7
  • 23

1 Answers1

8

As you have discovered, iOS has no public API for getting the device's PPI.

These apps probably have a hardcoded list, as you speculated. There are under a hundred hardware device ids (see this list for example), and only a handful of different PPIs:

  • non-retina iPhone, iPod touch, and iPad mini: 163 PPI
  • retina iPhone (except 6+), iPod touch, and iPad mini: 326 PPI
  • iPhone 6+: 401 PPI
  • non-retina iPad: 132 PPI
  • retina iPad: 264 PPI

I'd guess the makers of these apps don't usually test their apps with every device. And unless you've checked the apps, there's no reason you should believe the apps are more accurate than the PPIs listed above.

To detect the iOS device type, check the answers to this question.

Community
  • 1
  • 1
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Ugh. Thanks for your answer, but that confirms my fears. So if I were to do a similar thing, I would have to detect the device, out of a list of <100 (should I be able to find a ready-made class for this?), get the PPI for the detected device. I would then square root the PPI to find out how many pixels are in an inch, and then I could draw the ruler according to that calculation. Does that sound good? So when a new device is released, I need to check it to see if the PPI has changed, and if it has, I need to update the hard-coded list? – Invalid Memory Feb 18 '15 at 15:35
  • You don't need to take a square root. The PPIs I listed are measure along the screen edge, not the diagonal. I have updated my answer to help you find the device type. – rob mayoff Feb 18 '15 at 22:39
  • Here are some ppi per device list: 401: 6+ ; 326: 5s,6,8, XR,11, ; 458: x,12ProMax, 11ProMax ; 460: 12 ; 476: 12 mini – Andres Paladines Jun 22 '21 at 17:04