Reputation: 27399
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 [email protected]
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
Upvotes: 0
Views: 177
Reputation: 35925
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.
Upvotes: 1
Reputation: 4805
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
Upvotes: 1
Reputation: 930
[[UIDevice currentDevice] model];
[[UIDevice currentDevice] systemName];
[[UIDevice currentDevice] systemVersion];
Detect retina screen/iPhone 4 in iPhone SDK
Upvotes: 1
Reputation: 1290
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 [email protected] automatically.
Upvotes: 3