0

I'm moving my application from 3.x to 4.x as I prepare for the app store and found that I need to have 2 copies of all my custom pngs - my question is how can I determine what img to show and when. Example - how do I know to show the Find.png vs the Find@2x.png

Is it "safe" or "correct" to look for 4.x specific apis or does the iphone have a way to determine what platform you are on at runtime?

Thank you in advance

Toran Billups
  • 26,741
  • 39
  • 151
  • 265

4 Answers4

3

When you use standard APIs, the phone handles grabbing the @2x version when necessary. For example if you use [UIImage imageNamed:@"Find.png"]; and run on an iPhone 4, it would load Find@2x.png automatically.

Ben Cochran
  • 1,280
  • 11
  • 13
1
[[UIDevice currentDevice] model];
[[UIDevice currentDevice] systemName];
[[UIDevice currentDevice] systemVersion];

Detect retina screen/iPhone 4 in iPhone SDK

Community
  • 1
  • 1
Erick Smith
  • 878
  • 7
  • 25
1

If you use the imageNamed: method of UIImage the @2x business is handled for you.

Otherwise you can check the scale of the screen as in this question

Community
  • 1
  • 1
Alex Deem
  • 4,627
  • 1
  • 20
  • 24
1

If your application is running on (I believe) iOS 4.2 or greater and the images are PNG files you can replace you calls of:

[UIImage imageNamed:@"Find.png"];

with simply:

[UIImage imageNamed:@"Find"];

On the later versions of the OS imageNamed attempts to treat the incoming parameter as a root name to an image instead of the specific image name itself. In such a case it has the intelligence built-in to load the graphic most appropriate for the device.

fbrereto
  • 34,870
  • 18
  • 119
  • 177