我有一个 64px x 64px redSquare.png 文件,分辨率为 326ppi。我将其绘制在 View Controller 窗口的左上角,如下所示:
myImage = [UIImage imageNamed:@"redSquare.png"];
myImageView = [[UIImageView alloc] initWithImage:myImage];
[self.view addSubview:myImageView];
鉴于 iPhone 4S 的屏幕分辨率为 960x640 (326ppi),应该有足够的空间容纳 9 个以上的方 block ,以容纳第一个方 block 。但只能再容纳 4 个人。即,绘制的正方形比我的测量值应大。
// even tried resizing UIImageView in case it was
// resizing my image to a different size, by adding
// this next line, but no success there either :
myImageView.frame = CGRectMake(0, 0, 64, 64);
我相信这与设备“翻译”我的像素的方式有关。我在 Apple 的 documentation 中了解到点与像素之间的区别但它没有提到如何解决这个问题。我知道我正在以像素为单位进行测量。我应该用点来衡量吗?我怎样才能做到这一点?我究竟该如何调整图像大小,以便它可以在旁边容纳 9 个相同大小的方 block (即在同一水平面上......)?
谢谢
最佳答案
要在 Retina 显示屏上以全分辨率显示图像,需要在其名称末尾附加 @2x
。实际上,这意味着您应该将当前使用的图像保存为 redSquare@2x.png
,并将该图像的 32x32 像素版本保存为 redSquare.png
。
完成此操作后,无需更改代码。将根据设备的功能显示适当的图像。这将使您的应用能够在 Retina 和非 Retina 设备上正确呈现。
关于objective-c - 如何覆盖点到像素 iOS 特异性并以正确的尺寸绘制图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12020099/