iPhone 5 - what naming convention the new images have to follow?

20,078

Solution 1

The new default is [email protected]. (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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Share:
20,078
Duck
Author by

Duck

Updated on July 23, 2022

Comments

  • Duck
    Duck almost 2 years

    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
    [email protected]  and
    [email protected]
    

    what about the other images used by an app?

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

  • Duck
    Duck over 11 years
    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.
  • wattson12
    wattson12 over 11 years
    @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
  • Duck
    Duck over 11 years
    this is the case why I am asking, I mean, I have to load fullscreen images that are not intended to be stretched... 😃 thanks!
  • David
    David over 11 years
    Can you please attache the code snippet to your response since the link does not work. Thank you.
  • CarlJ
    CarlJ over 11 years
    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
  • miho
    miho over 11 years
    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
    miho over 11 years
    Oh, extension, I see. It shouldn't be that hard to include a check and remove of the extension of the passed paths.
  • Angel G. Olloqui
    Angel G. Olloqui over 11 years
    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!
  • rob5408
    rob5408 over 11 years
    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 "[email protected]". 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!
  • David Doyle
    David Doyle over 11 years
    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.
  • miho
    miho over 11 years
    There aren't any ~568h devices which aren't retina. So assuming that 568h pixels are always @2x isn't an issue.
  • David Doyle
    David Doyle over 11 years
    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 [email protected]) not an iPhone 5 image, as the code snippet will automatically search for [email protected].
  • bendahmon
    bendahmon almost 11 years
    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?)
  • shim
    shim almost 11 years
    Why is the default image a hyphen but other images are supposed to use a tilde '~'?