问题描述
|
我有一个TabBarController应用程序,该应用程序从Web获取所有图像,包括tabBarController的图标。我想要的是当设备具有视网膜显示时图像看起来不错。
这就是我在做什么:
根据屏幕比例缩小图像尺寸。
设置视图内容比例:imageView.contentsScale = [UIScreen mainScreen] .scale;
对于使用UIImageView的标准图像来说,它运行良好,但是我无法弄清楚如何对UITabBarItems执行此操作,因为我无法访问框架或contentScale。
有任何想法吗?
谢谢!
解决方法
创建UIImage时,可以将视网膜尺寸图像资源的图像比例设置为2.0。以下是我的操作方式示例:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *image = [UIImage imageWithData:data];
CGImageRef cgimage = image.CGImage;
image = [UIImage imageWithCGImage:cgimage scale:2.0 orientation:UIImageOrientationUp];
现在,您可以在UITabBarItem上使用此图像。
,您可以创建图像的两个版本,并将其命名为30px的image.png和60px的image@2x.png。
然后使用:
UIImage *image = [UIImage imageNamed:@\"image.png\"];
将根据设备上的显示加载正确的分辨率图像。
,如何确定设备是否为视网膜,并相应地下载其他资产呢?