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 withUIImage imageNamed:
. - Do I need to add a
@3x
declaration to the end of the file? My naming conventionpic.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?
source to share
Sol: [UIImage imageNamed:@"pic"]
enough, not [UIImage imageNamed:@"pic.png"]
.
Cause:
- The device automatically detects
pic@2x.png
andpic@3x.png
after adding to the project. - If you have not added any tools
pic@2x.png
orpic@3x.png
, the device will automatically download the pic.png file. - So, you just add this line
[UIImage imageNamed:@"pic"]
to your project.
source to share
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"]
source to share