gpt4 book ai didi

ios - 添加 iOS @1x、@2x、@3x PER 设备,如何?

转载 作者:搜寻专家 更新时间:2023-10-31 08:08:37 25 4
gpt4 key购买 nike

我最近问了一个关于为什么我们使用上面列出的 3 种不同图像类型的问题,并得到了很好/详细的回答。这也让我质疑其他事情......

假设我在 XCode(使用 SWIFT)中工作,并且在 iPhone 上具有三种图像大小 @1x、@2x、@3x 用于特定的 say UIImage。现在,我希望它在 iPad 上看起来不错,所以我添加了一些缩放比例。但是,这会改变 iPad 所需的 1x、2x、3x 图像的大小,因此我需要再制作 3 个图像来补偿新尺寸。现在 XCode 将如何区分这两者?我需要检查我使用的屏幕尺寸然后选择图像吗?

我读到 Assets 可以帮助我,但这只涉及 iPhone 与 iPad,如果我在 iPhone 4、5、6 和 iPad 上缩放我的图像会怎样。这是很多不同尺寸和@x 图像,而且我读到 Apple 不喜欢设备检查,所以我不确定那会怎样。

我希望这是有道理的。我在每台设备上获得 @1x、2x、3x,但如果我的应用程序是为通用设备使用而设计的,那么我如何在代码中为适当的设备管理所有这些不同的大小?

最佳答案

你真的应该使用图像 Assets 目录。这几乎太容易了。这是 Apple 给出的定义,因此您知道这不是道听途说:

Image sets: Used for most types of images, an image set contains all the versions, or representations, of an image that are necessary to support various devices and scale factors.

然后继续下去:

Each set in an asset catalog has a name. You can use that name to programmatically load any individual image contained in the set. To load an image, call the platform specific class method, passing in the name of the set that contains the image. The OS will load the image from the set that is most appropriate for the current scale factor

所以你真的没什么可做的。我不知道你在哪里听到相反的声音

See Documentation here

关于ios - 添加 iOS @1x、@2x、@3x PER 设备,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32381322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com