您的位置:首页 > 移动开发 > IOS开发

iOS8 两种image方法 对@2x @3x 加载选取的解析

2015-06-01 16:59 393 查看
取image方法1

UIImage *image = [UIImageimageNamed:@"图片名字"];//没有
@2x @3x

输出:

2015-06-01 16:30:33.219 test[4676:1829040] device: iPhone 4s *** imageData.length: 1107

2015-06-01 16:29:30.001 test[4617:1819270] device: iPhone 5 *** imageData.length: 1107

2015-06-01 16:27:57.803 test[4535:1810875] device: iPhone 5s *** imageData.length: 1107

2015-06-01 16:25:45.310 test[4476:1798634] device: iPhone 6 *** imageData.length: 1107

2015-06-01 16:33:11.060 test[4751:1848019] device: iPhone 6 Plus *** imageData.length: 1840

[b]取image方法2
[/b]

NSString *path = [[NSBundlemainBundle]pathForResource:@"图片名字"ofType:@"png"];//没有 @2x
@3x


UIImage *image = [[UIImagealloc]initWithContentsOfFile:path];

注:initWithContentsOfFile 方法需要@1x的图片 不然获取不到图片

输出:

2015-06-01 16:50:09.486 test[5168:1954713] device: iPhone 4s *** imageData.length: 1107

2015-06-01 16:49:44.608 test[5116:1951056] device: iPhone 5 *** imageData.length: 1107
2015-06-01 16:44:16.885 test[4974:1921579] device: iPhone 5s *** imageData.length: 1107
2015-06-01 16:45:40.441 test[5032:1932897] device: iPhone 6 *** imageData.length: 1107
2015-06-01 16:42:36.905 test[4920:1907182] device: iPhone 6 Plus *** imageData.length: 1840

通过测试 可以发现两种方法在iPhone 6 Plus 上都会优先加载
@3x 图片,在其他测试机型上加载 @2x 图片。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  2x 3x