带有图像集名称的 UIImage

UIImage with image set name

我想使用资产中的图像集实例化一个 UIImage。我尝试了这两种方法-

[UIImage imageNamed:myImageSetName]

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

在这两种情况下,它似乎 return 分辨率为 320*480 的图像,这是图像的默认图像的分辨率 set.I 尝试 运行 在 iPhone 6s plus (11.3) 和 iPad pro 12.9 英寸 (11.3) 模拟器。所以我希望决议与此大不相同。

我应该如何根据 device/OS 获得具有适当分辨率的图像?还是我猜错了?

这个结果符合预期。 如果你想要当前设备上的真实图像大小,你需要考虑屏幕分辨率。

例如:UIScreen.mainScreen().scale 或者对于计算,您可以根据您的设备使用 x2 或 x3。

所以对于 iPhone 6s 加上它将是 (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

您可以在 mac 上使用名为 App Icon Gear 的应用。并使用它将图像切割成您想要的尺寸。试试吧,可能对你有帮助。或者检查一些关于你的 imageView 的约束。