5

There are iPhone 6 and iPhone 6 plus device available from apple.

  • I have three pics including @2x and @3x. When I load image using UIImage imageNamed:.
  • Do I need to add @3x ad the end of file? My naming convention is pic.png, pic@2x.png, pic@3x.png.
  • Do I need to do like first check the running device is iPhone 6 and then [UIImage imageNamed:@"pic@3x.png"] or just [UIImage imageNamed:@"pic"] and the device will automatically use the right image for the right device?
Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
yong ho
  • 3,892
  • 9
  • 40
  • 81
  • In the new Xcode project tree, there is a Image.xcassets (maybe you need to add one and link it up if it's an old project) file. If you open it, you can import image assets. That's how we managed our image assets these days, more cleaner and makes the project tree shorter. – Zhang Nov 07 '14 at 09:14
  • 1
    the sole purpose of this suffixes it to enable automatic selection of the right version. – vikingosegundo Nov 07 '14 at 09:24

3 Answers3

11

Sol: [UIImage imageNamed:@"pic"] is enough instead of [UIImage imageNamed:@"pic.png"].

Reason:

  • Device automatically detect pic@2x.png & pic@3x.png once you added into you project.
  • If you not added any pic@2x.png or pic@3x.png image means device will load pic.png automatically.
  • So you just add this line [UIImage imageNamed:@"pic"] in your project.
Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
  • Could you please help me this http://stackoverflow.com/questions/43995059/how-to-add-images-for-different-screen-size-from-assets-xcassets-in-xcode-8 ? – May Phyu May 16 '17 at 07:49
2
[UIImage imageNamed:@"pic"]

is enough.

Suffixes (@2x for iPhone 4 to 6 and @3x for iPhone 6 plus) are added automatically if image with this suffix is found.

nicael
  • 18,550
  • 13
  • 57
  • 90
0

TLDR: be sure to include @2x images if you are supporting iOS 6/7, or specify "*@3x" in imageNamed.

If you support older version of iOS (6/7), you need to do 1 of 2 things.

First option: include all versions of an image (normal, 2x, 3x). Preferred.

Second Option: if you only include a @3x image, [UIImage imageNamed"pic"] will work great on iOS 8 (downscaling the 3x image to 2x or 1x size as needed), however, it fails on iOS 7 since iOS 7 wasn't ever aware of @3x. You should use [UIImage imageNamed"pic@3x"]

scosman
  • 2,343
  • 18
  • 34