Does the UIImage imageNamed need the @ 3x suffix?

There are devices iPhone 6

and iPhone 6 plus

available from apple.

  • I have three photos including @2x

    and @3x

    . When I load the image with UIImage imageNamed:

    .
  • Do I need to add a @3x

    declaration to the end of the file? My naming convention pic.png

    , pic@2x.png

    , pic@3x.png

    .
  • Do I need to check first if the running device is working iPhone 6

    and then [UIImage imageNamed:@"pic@3x.png"]

    or simply [UIImage imageNamed:@"pic"]

    and the device will automatically use the correct image for the correct device?
+3


source to share


3 answers


Sol: [UIImage imageNamed:@"pic"]

enough, not [UIImage imageNamed:@"pic.png"]

.

Cause:



  • The device automatically detects pic@2x.png

    and pic@3x.png

    after adding to the project.
  • If you have not added any tools pic@2x.png

    or pic@3x.png

    , the device will automatically download the pic.png file.
  • So, you just add this line [UIImage imageNamed:@"pic"]

    to your project.
+10


source


[UIImage imageNamed:@"pic"]

      

...



Suffixes (@ 2x for iPhone 4-6 and @ 3x for iPhone 6 plus) are added automatically if an image with that suffix is ​​found.

+2


source


TL; DR: be sure to include @ 2x images if you support iOS 6/7, or include "* @ 3x" in imageNamed.

If you support an older version of iOS (6/7), you need to do one of two things.

The first option is to include all versions of the image (normal, 2x, 3x). Preferred.

Option two: if you only include the @ 3x image [UIImage imageNamed"pic"]

works fine on iOS 8 (downscaling the 3x image to 2x or 1x size as needed) however it doesn't work on iOS 7 as iOS 7 wasn 'ever known @ 3x ... You must use[UIImage imageNamed"pic@3x"]

0


source







All Articles