我正在尝试创建一个与视网膜和非视网膜显示器兼容的应用程序。我使用高分辨率图像并让操作系统将其缩小以适应非视网膜显示器。
图像名为 [email protected]我用相同的名字加载。这是可行的,并且图像在两种设备类型上以相同的相对尺寸显示。不幸的是,非视网膜显示器上调整大小后的图像质量远非理想。
self.navigationItem.rightBarButtonItem.image = [localAssets imageAtPath:@"content/home/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2152445555484f46526113590f514f46" rel="noreferrer noopener nofollow">[email protected]</a>"];
+ (UIImage*)imageAtPath:(NSString*)path;
{
NSString* extension = [path pathExtension];
path = [path stringByDeletingPathExtension];
NSString* filePath = [[NSBundle mainBundle] pathForResource:[path lastPathComponent]
ofType:extension
inDirectory:[path stringByDeletingLastPathComponent]];
UIImage* theImage = [UIImage imageWithContentsOfFile:filePath];
if(!theImage)
{
NSLog(@"Error no file found at %@", [path stringByAppendingPathExtension:extension]);
}
return theImage;
}
视网膜:
旧版:
最佳答案
如果您自己调整图像大小,并将它们另存为 xxx.png 和 [email protected] ,然后您可以将它们用作“xxx”,并且当使用 Retina 显示屏时,iOS 将自动使用 @2x 版本。
关于objective-c - 调整大小后的 UIImage 质量较差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11351929/