我有一个TabBarController应用程序,可以从Web获取所有图像,包括tabBarController的图标。我想要的是当设备具有视网膜显示时图像看起来很好。
这就是我在做的事情:
使用UIImageView对标准图像工作正常,但我无法弄清楚如何为UITabBarItems执行此操作,因为我无法访问框架或contentScale。
有什么想法吗?
谢谢!
答案 0 :(得分:3)
创建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上使用此图像。
答案 1 :(得分:2)
您可以创建两个版本的图像,并为30px命名为image.png,为60px命名为image@2x.png。 然后使用:
UIImage *image = [UIImage imageNamed:@"image.png"];
将根据设备上的显示加载正确的分辨率图像。
答案 2 :(得分:0)
如何判断设备是否为视网膜,并相应下载不同的资产?