Universal application iPad/iPhone image naming convention?
Asked Answered
W

5

14

In my application I need to get the correct image based on the device iPad/iPhone 4/iPhone 3 device.

For example:

I have an image named a.png (width 40,height 20) for iPhone 3/iPod, and [email protected] (width 80,height 40) for iPhone 4.

If I mentioned the code

UIImage *myImage=[UIImage imageNamed:@"a.png"];

myImage contains (80*40) image if it's iPhone 4. myImage contains (40*20) image if it's iPod/iPhone 3.

My question is how do I get the image for iPad (60*30) like above naming convention.

I tried giving a~ipad.png as an image name and it's not working. Can you point out where there is a mistake?

And if I use the condition using [UIDevice currentDevice]; isIpod -> load(60*30) image otherwise load images for iPhone/iPod it's working fine.

But I need to get it to work without using the condition, and using the naming convention like a.png for iPhone/iPod, [email protected] for iPhone 4 and likewise for iPad.

Thanks in advance.

Winton answered 28/10, 2010 at 7:4 Comment(0)
P
21

I know it is old post, but I think Screenshot gives more clear idea about naming convention.

enter image description here

With latest devices: button@3x~iphone.png and button@3x~ipad.png

Precincts answered 2/9, 2013 at 13:45 Comment(0)
D
18

According to this Apple doc, there is an image naming convention for devices:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html#//apple_ref/doc/uid/10000051i-CH7-SW17

It says to use "~iphone" for iPhone, and no suffix for iPad. Though anecdotally I have been told that "~ipad" also works.

Dillondillow answered 19/1, 2012 at 16:59 Comment(1)
The updated link to Apple documentation for device specific resource naming convention.Gnarl
D
8

There is no image naming convention for iPad, it's only for retina displays so that your images will appear crisp. If you want to support iPad then you need to create a separate layout for it (separate xib), even separate set of images in most cases because you were given a bigger layout.

You can, however, create a naming convention for yourself and pass the string name to a static function that will convert the name to an iPad / iphone depending on the device.

E.g.

[UIImage imageNamed: [MyAppUtils getImageName:@"a.png"]];

and inside the getImageName function, you can do your conversion (use the same name if iphone, else rename to something else)

Davit answered 28/10, 2010 at 7:11 Comment(0)
P
7

Further to Nate's post, the specific documentation from Apple describing the naming convention can be found at:

Supporting High-Resolution Screens - Updating Your Image Resource Files

According to the link, the naming convention pattern is as follows:

  • Standard: <ImageName><device_modifier>.<filename_extension>
  • High resolution: <ImageName>@2x<device_modifier>.<filename_extension>

For example: "MyImage@2x~ipad.png" for a high-res iPad-specific image or "MyImage~iphone.png" for a standard-res iPhone-specific image.

Prosperous answered 7/9, 2012 at 22:34 Comment(0)
D
0

I am using a "Resource Manager" that I developed first before creating any application. This Resource Manager can decide about the naming convention after loading the resource configuration files (mostly XML). This way everything is transparent to the programmer of the GUI, you only need to worry about creating the content :)

Devoice answered 28/10, 2010 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.