简体   繁体   中英

How to name images in XCode Asset Catalog in the right manner?

I try to organise the images in XCode Asset Catalog, but I am kind of confused:

(1) I try to create new folders for different group of images. However, I can access an image without specifying the folder name, such as:

let image = UIImage(named: "btn_tabsetting")

Should I give each image a different name even I already have put them in different folders?

(2) As shown below, in test folder, I create an image btn_tabsetting which has the same name as the one in the other folder. Why does XCode allow me to do this? When I call

let image = UIImage(named: "btn_tabsetting")

it actually loads the the one in Tab Setting View folder instead of the one in test folder, why is it so? What is the rule here?

I think maybe I misunderstand some important concepts in using the Asset Catalog, please help me to correct them.

在此处输入图片说明

According to docs

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.

So asset names should be unique. What I recommend is organize assets in logical groups and than prefixing each asset inside group with group name. For an example:

- 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

Xcode Automatically set different image name, if you have placed same name of images in Asset Catlog.

Suppose i have drop one image as xyz.png and then i again drop xyz.png in it, the xcode will rename it with xyz_1.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM