gpt4 book ai didi

ios - 如何以正确的方式命名 XCode Asset Catalog 中的图像?

转载 作者:行者123 更新时间:2023-11-29 00:54:08 34 4
gpt4 key购买 nike

我尝试在 XCode Asset Catalog 中组织图像,但我有点困惑:

(1) 我尝试为不同的图像组创建新文件夹。但是,我可以在不指定文件夹名称的情况下访问图像,例如:

let image = UIImage(named: "btn_tabsetting")

即使我已经将每个图像放在不同的文件夹中,我是否应该为每个图像指定不同的名称?

(2) 如下所示,在 test 文件夹中,我创建了一个图像 btn_tabsetting ,其名称与其他文件夹中的图像相同。为什么 XCode 允许我这样做?当我打电话时

let image = UIImage(named: "btn_tabsetting")

它实际上加载的是Tab Setting View文件夹中的内容,而不是test文件夹中的内容,为什么会这样?这里的规则是什么?

我想我可能误解了使用 Assets 目录的一些重要概念,请帮助我纠正它们。

enter image description here

最佳答案

根据文档

For any target in an Xcode project, the fully qualified name of an asset must be unique across all the asset catalogs and across all asset types. For example, it is an error to have an image set folder in one asset catalog called Llama.imageset and an image set with the same name in the same catalog or in a different catalog that is part of the same target. Similarly, it is an error to have both an image set folder called Llama.imageset and an app icon folder called Llama.appiconset in the same catalog or in a different catalog that is part of the same target.

因此 Assets 名称应该是唯一的。我的建议是将 Assets 组织在逻辑组中,然后为组内的每个 Assets 添加组名称前缀。例如:

- Icons (group)
- icon_gear
- icon_heart
- icon_edit
- TabBar (group)
- icon_tabbar_profile
- icon_tabbar_settings
- Settings (group)
- icon_settings_age
- icon_settings_name
- Streachables (group)
- streachable_profile_background
- streachable_product_background

关于ios - 如何以正确的方式命名 XCode Asset Catalog 中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37789590/

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