29

What is the new naming convention for images for the 4-inch retina display?

For an image named background.png you add @2x to the name ([email protected]) to tell iOS to use that one for devices with the retina display.

What would the suffix be for iPhone 5's screen size?

1

1 Answer 1

61

You can use my #defines to help you with these images:

#define isPhone568 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
#define iPhone568ImageNamed(image) (isPhone568 ? [NSString stringWithFormat:@"%@-568h.%@", [image stringByDeletingPathExtension], [image pathExtension]] : image)
#define iPhone568Image(image) ([UIImage imageNamed:iPhone568ImageNamed(image)])

Just give your images the [email protected] notation, and use iPhone568ImageNamed to get a name for standard name or iPhone 5/new iPod.

Usage example from the comments:

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:iPhone568ImageNamed(@"mainscreen.png")]];
10
  • Q: If the name is passed in as "foo.png" doesn't it end up converting to "foo.png-568h" instead? Sep 25, 2012 at 18:42
  • 7
    Ahh, what about this? #define iPhone568ImageNamed(image) (isPhone568 ? [NSString stringWithFormat:@"%@-568h.%@", [image stringByDeletingPathExtension], [image pathExtension]] : image) Sep 25, 2012 at 19:10
  • 2
    example of this with a background pattern: self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:iPhone568ImageNamed(@"mainscreen.png")]]; Oct 10, 2012 at 4:12
  • 1
    Do you mean when the device rotates? If so, in veiwDidLayoutSubviews. Otherwise, viewDidLoad is a good candidate.
    – Léo Natan
    Oct 21, 2012 at 3:07
  • 1
    @LudovicLandry It is inevitable if you want to have a precise 1:1 pixel mapping between the image and screen. Your suggestion can and will create upscale artefacts (blurring, for example).
    – Léo Natan
    Dec 19, 2012 at 15:25

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.