40

What name convention the new images have to have to be loaded by the new iPhone 5?

We see that we have to have 3 default images to be loaded by the device

Default.png
Default@2x.png  and
Default-568h@2x.png

what about the other images used by an app?

Is there a naming convention that will automatically load the correct image?

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Duck
  • 34,902
  • 47
  • 248
  • 470

4 Answers4

36

The new default is Default-568h@2x.png. (note hyphen)

There is no other corresponding change. If you need a different image for the new iPhone 5 screen then you have to create it as a separate name. There is no 1x/2x/new phone auto switching behavior.

Bot
  • 11,868
  • 11
  • 75
  • 131
jsd
  • 7,673
  • 5
  • 27
  • 47
  • 2
    the Default was just an example. I was talking about the other images the app has to load, but anyway, apparently it is up to the developer to select the right image. – Duck Sep 14 '12 at 20:26
  • @RubberDuck you dont really need to select which image to use in most cases: the iPhone 5 is a retina display, so it will use the same 2x images as the iPhone 4 and 4S. The only time you would need to select is full height images where you are not stretching – wattson12 Sep 14 '12 at 20:53
  • 3
    this is the case why I am asking, I mean, I have to load fullscreen images that are not intended to be stretched... thanks! – Duck Sep 14 '12 at 21:02
  • Why is the default image a hyphen but other images are supposed to use a tilde '~'? – shim Jul 11 '13 at 03:06
16

If you are looking for something similar to ~iPad or ~iPhone (like ~586h) there isn't anything build in like that. But you can easily add it yourself by expanding UIImage class.

Have a look at this source snippet (UIImage+Retina4) for information about how to achieve. Just add this UIImage category and there will be support for ~568h@2x files.

miho
  • 11,765
  • 7
  • 42
  • 85
  • 1
    Can you please attache the code snippet to your response since the link does not work. Thank you. – David Sep 20 '12 at 18:33
  • i take a look in your source snippet and for me it doenst work, because, you are never returning a UIImage, you create a infity loop and you doesnt care about a path extension – CarlJ Sep 25 '12 at 14:42
  • Where is an infinity loop? Works for the way I use the images but I don't check if there are other ways to use this function. Could you describe it a bit more detailed? – miho Sep 26 '12 at 04:40
  • Oh, extension, I see. It shouldn't be that hard to include a check and remove of the extension of the passed paths. – miho Sep 26 '12 at 04:43
  • 1
    meccan, you are not creating an infinity loop. The methods are swizzled! the callings to retina4ImageNamed will actually call the original imageNamed method of UIImage. Read about method swizzling if you don't understand it enough! – Angel G. Olloqui Sep 28 '12 at 08:36
  • There's a bug in the linked code, if you try [UIImage imageNamed:@"background.png"] it builds a proper path, but then tries to locate "background-568h@2x.png.png". So switch 'NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageNameMutable ofType:@"png"];' to 'NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageNameMutable ofType:@""];'. Other than that it works great, thanks! – rob5408 Oct 23 '12 at 10:16
  • Couple of bugs there: 1) The code doesn't infinitely recurse, but thanks to the wonders of swizzling it sure does read that way. A better approach would be to not rely on swizzling. 2) The code never checks for whether you want @2x or -568@2x ... it automatically assumes that you want -568@2x, so I can't see it being compatible with iPhone 4 retina devices. – David Doyle Jan 16 '13 at 10:36
  • There aren't any ~568h devices which aren't retina. So assuming that 568h pixels are always @2x isn't an issue. – miho Jan 16 '13 at 11:53
  • Its on the first line - the code checks for if there's an @ symbol in the string. That's a little unfortunate if you were after an iPad image (such as image@2x.png) not an iPhone 5 image, as the code snippet will automatically search for image-568@2x.png. – David Doyle Jan 16 '13 at 11:54
  • I've added these two files to my project. However, do I have to do anything more to make sure the "swizzling" actually takes place? I was also confused about the swizzling, are the function pointers actually replaced, so that deliberately invoking retina4ImageNamed would actually invoke the old imageNamed instead? (while invoking imageNamed would invoke retina4ImageNamed?) – bendahmon May 25 '13 at 11:45
9

I solve this problem here. Just add @2x~568h suffix to images or ~568h to xib's. Also you can use this images in xib's.

Shimanski Artem
  • 1,240
  • 1
  • 11
  • 7
2

With the introduction of Asset Catalog in Xcode 5, all you have to do with the images is simple drag and drop to its corrosponding related areas. Everything else will be handled by the Xcode itself.enter image description here.

You can create new catalog by going to the above mentions option in the screenshot.

Pranjal Bikash Das
  • 1,092
  • 9
  • 27