views:

85

answers:

4

Apple says you must have @2x versions of your images and use a stuff like

UIImage* anImage = [UIImage imageNamed:@"Button"]; // without the extension

That will select the lowres and hires versions of Button image, depending on the iPhone version (3G/3GS or 4). But what if the app is for iPad too?

Will the iPad load the Button image even if I don't specify the extension?

thanks.

+1  A: 

Yes, it will load the standard (lores) version.

Edit: Don't forget to test on the simulator or real device, as there are some twiddles, but imageNamed: has proven to work well so far.

Eiko
+2  A: 

Either

UIImage* anImage = [UIImage imageNamed:@"Button"]; // without the extension

or

UIImage* anImage = [UIImage imageNamed:@"Button.png"]; // with the extension

will work on iOS4, since apple basically discourage you from using any other image than PNG you can omit the exertion.

Both work for @2x.png files as well. Make sure the @2x files have been added to your project.

John Ballinger
I've done that but the images are not loading in hires... at least not on the simulator (no iPhone 4 soon on my country). Can you please confirm if the hires images load on the simulator, once you have them on your project? thanks!
Digital Robot
Yes they show up fine.
Joonas Trussmann
+5  A: 

Will the iPad load the Button image even if I don't specify the extension?

No. From the doc:

  • Special Considerations

    On iOS 4 and later, the name of the file is not required to specify the filename extension. Prior to iOS 4, you must specify the filename extension.

Since iPad is running 3.2, you need to include the .png part. However, writing

UIImage* anImage = [UIImage imageNamed:@"Button.png"];

will not prevent the system from finding [email protected] on 4.0.

KennyTM
+2  A: 

as a complement to the answer, I must mention this page:

the problem is that the SDK is broken and despite Apple mentioning that other methods beyond imageNamed load the @2x images, they don't. Shame on Apple to make us lose time when their SDK is broken.

the mentioned link has the solution for the problem, using a way around.

Digital Robot