views:

39

answers:

1

Anyone know if there's a way to get the screen density (ppi) of the device at runtime? It'd be nice to not have to hard code the different densities in case apple switches it up in the future...

+1  A: 

Don't use pixels, you can use Points and the OS will handle the display for you.

-- UPDATE --

Apple covers this pretty extensively in "Introduction to Resolution Independence Guidelines" which can be found at http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/HiDPIOverview/

and in the iOS programming guide which can be found at:

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html

See the section titled: supporting high resolution screens. You do not have to hard code different densities, and if you are using core graphics they scale automatically.

Joshua Smith
Points are not very useful if you need the display to exactly match the size of some physical object outside of the phone, like a coin so many mm across. You need true ppi.
hotpaw2
Additionally to make images look their best you want to use an image matched to the screen's ppi.
MZamkow