【发布时间】:2015-02-20 14:50:22
【问题描述】:
我需要关于如何在不同分辨率的 iPhone 中使用图像的建议。
我们知道,对于 iPhone3gs 和 iPhone 4,我们需要@1x 图像。
对于 iPhone4s 和 iPhone 5,6,我们需要 @2x 图像。
对于 iPhone 6+,我们需要@3x 图片。
我正在考虑以两种方式添加图片资源。
方式 1 -
abc.png size 20X20
abc@2x.png size 40X40
abc@3x.png size 60X60
在访问我们使用的图像时
UIImage *img = [UIImage imageNamed:@"abc.png"];
这里在非retina显示ios会自动选择abc.png 对于 iphone 4s,5,6 它会自动选择 abc@2x.png 对于 iphone6+,它会自动选择 abc@3x.png
方式 2 -
abc.png size 20X20
abc@2x.png size 40X40
abc_iphone5or6.png size 25X25
size is bigger because resolution is big, we need to show big icon , if we use way 1 then it will show 20X20 size icon and will look smaller on big screens
abc_iphone5or6@2x.png size 50X50
abc_iphone6+.png size 35X35
size is bigger because resolution is big, we need to show big icon , if we use way 1 then it will show 20X20 size icon and will look smaller on big screens
abc_iphone6+@3x.png size 70X70
if(is_iphone4or4s){
UIImage *img = [UIImage imageNamed:@"abc.png"];
}
else of (iphone5or6){
UIImage *img = [UIImage imageNamed:@"abc_iphone5or6.png"];
}
else{
UIImage *img = [UIImage imageNamed:@"abc_iphone6+.png"];
}
请建议应该使用哪种方法。我应该只添加 abc.png、abc@2x.png 和 abc@3x.png 还是应该为每个分辨率使用单独的视网膜和非视网膜图像?
谢谢
【问题讨论】:
-
你应该使用第一种方法,你不需要 if 语句。让 iPhone 为您完成工作。这就是命名约定的用途。
-
使用第一种方法。大小不必成比例,但通常是成比例的。另外,如果你只支持 iOS 7,你可以只创建一个 xcassets 文件。
标签: ios objective-c xcode screen-resolution