具有图像集名称的UIImage

时间:2018-06-29 06:55:57

标签: ios uiimage

我想使用Assets中设置的图像实例化UIImage。我尝试了这两种方法-

[UIImage imageNamed:myImageSetName]

[UIImage imageNamed:myImageSetName inBundle:nil compatibleWithTraitCollection:nil]

在这两种情况下,似乎都返回分辨率为320 * 480的图像,这是图像集默认图像的分辨率。我尝试在iPhone 6s plus(11.3)和iPad pro 12.9 inch(11.3)上运行)模拟器。因此,我希望分辨率会与此不同。

如何根据设备/操作系统获得具有适当分辨率的图像?还是我假设有什么问题?

2 个答案:

答案 0 :(得分:1)

此结果符合预期。 如果要在当前设备上获得真实图像的大小,则需要考虑屏幕分辨率。

例如:UIScreen.mainScreen().scale 或者为了进行计算,您可以根据设备使用x2或x3。

因此,对于iPhone 6s plus来说,它将是(2 x 320)*(2 x 480)

对于显示,如果您已设置所有图像资产,iOS会为您处理。

要获取实际的图像尺寸,您需要将缩放比例用于计算: If you multiply the logical size of the image (stored in the size property) by the value in this property, you get the dimensions of the image in pixels. https://developer.apple.com/documentation/uikit/uiimage/1624110-scale

答案 1 :(得分:0)

您可以在Mac上使用名为App Icon Gear的应用程序。并使用它将图像切成您想要的尺寸。试试看,可能对您有帮助。或查看有关imageView的一些约束条件。

相关问题