经测试:
假设有两张图片名为:test_t@2x.png 、test_t@3x.png
使用initWithContentsOfFile
NSString *path = [[NSBundle mainBundle] pathForResource:@"test_t@2x" ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
在ipone5 s、iphone6和iphone6 plus都是需要带上@2x/@3x的图片后缀名,否则程序会报错,加载的图片取决于你写的是@2x 还是 @3x;
使用imageWithName
UIImage *image = [UIImage imageNamed:@"test_t"];
在ipone5 s、iphone6和iphone6 plus都是不需要带上@2x/@3x的图片后缀名,程序会优先加载@2x 的图片 ,但如果需要加载@3x 的图片,你需要写上@3x;
使用Xib 加载图片,和imageWithName 类似,但有一点不同的就是你不能匹配 test_t@2x.png ,要么匹配 test_t .png ,程序会自动加载 test_t@2x.png 的图片,要么匹配 test_t@3x.png ,程序加载 test_t@3x.png 的图 ;
最后一个疑问,不知道为什么 iPhone6 plus 也会优先加载 @2x 的图片,在图片名为 test_t .png的情况下 ?
那这样的话,@3x 的图片意义就不大了,若每次手动去测试的话会比较麻烦,这也不科学啊~
希望有朋友能够解答一下,谢谢 ~O(∩_∩)O