4

I already know about iOS app non-retina and retina images concept. But assume that the project which created for retina device then normally image name should be "myImageName@2x.png" but can I use it as "myImageName.png" instead of "myImageName@2x.png" ? There are no any changes of size of image, just changed name of image "myImageName@2x.png" TO "myImageName.png".

Is it valid or not ?

Community
  • 1
  • 1

3 Answers3

2

No, You can't use "myImageName.png" instead of "myImageName@2x.png" if you created for the app for retina devices because to support the ratina device you must have image name "myImageName@2x.png".

If you use "myImageName.png" instead of "myImageName@2x.png" then apple consider that this UI part only implemented for non retina display devices.

Yash Vyas
  • 558
  • 4
  • 24
  • Apple not check for size of the image it will consider the naming convention for the image name. – Yash Vyas Mar 26 '14 at 05:33
  • what if "apple consider that this UI part only implemented for non retina display devices"? Will the UI part look different? – KudoCC Mar 26 '14 at 05:49
  • 1
    Ok..Have you any documentation/ link / tutorial that suggest by apple that you are saying this ? Aad really thanks to you for give me suggestion thanks again. :) –  Mar 26 '14 at 05:50
  • https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html#//apple_ref/doc/uid/TP40007072-CH6-SW5 – Yash Vyas Mar 26 '14 at 06:25
  • @KudoCC: The UI Part not look different but apple created the image naming conventions. – Yash Vyas Mar 26 '14 at 06:56
2

I will demonstrate it in 2 situations.

Image in xib

If you use an image in xib, it will inspect the filename of the image, if it has the @2x suffix, it size will divide by 2. I have an example here. I have an image named refresh.png, its size if 40*40 in pixel, if I use it in xib, it present like this:enter image description here and if I rename it to refresh@2x.png, it present :enter image description here

Image load manually

If you load the image by code, the property scale of UIImage tells what happened.

@property(nonatomic, readonly) CGFloat scale Discussion If you load an image from a file whose name includes the @2x modifier, the scale is set to 2.0. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0.

If you multiply the logical size of the image (stored in the size property) by the value in this property, you get the dimensions of the image in pixels.

Conclusion: To answer your question, the answer is no obviously. I think the important thing is the difference between pixel and point. On non-retina device, one point is one pixel, on retina device one point is 2*2 pixel. In my example, Xib will arrange the image according to its size property (which reflects the logical size of the image and is measured in points in ios 4.0 and later.). If your image is 40*40 in pixels and without the @2x suffix, its size will be 40*40 point and its scale will be 1.0. If you rename it with @2x suffix, its size will be 20*20 point and scale will be 2.0.

Naming the image resource for retina device with @2x suffix is a convention, so just follow it or you will be in trouble.

More about imageNamed: method 、scale and size property of UIImage here.

KudoCC
  • 6,912
  • 1
  • 24
  • 53
  • Good explanation mate.. if OP use `refresh.png` in retina device then how many chances to reject apps by apple? – iPatel Mar 29 '14 at 04:57
  • @iPatel It's hard to tell, maybe apple doesn't care about that if the user interface looks good. – KudoCC Mar 29 '14 at 06:34
0

The thing about retina/non-retina it is not the name of the image, but the size of the image. When you are creating images for your app, you should provide two sizes of each image: the one suffixed with @2x should be double size of the "normal" image (without @2x suffix). Otherwise, if the two have the same size, having two different images is pointless. If you created the images in a retina device, then your original image should be named with @2x suffix, and then you should scale down the image and save it without @2x suffix.

Afterwards, when you want to load the image, for example with [NSImage imageNamed:imageName], you should provide the image name without extension and without suffix: [NSImage imageNamed:@"myName"]. The app will then select the appropriate file according to the type of device. Files are named "myName.png" and "myName@2x.png", but don't call [NSImage imageNamed:@"myName.png"] or [NSImage imageNamed:@"myName@2x.png".

Hope this helps.

George
  • 1,235
  • 10
  • 23