Referencing image in a folder in asset catalog

后端 未结 2 1739
孤独总比滥情好
孤独总比滥情好 2021-02-05 04:00

In an asset catalog you can create folders.

Inside the folders all the image names have to be unique.

If you have an image called myImage and you tr

2条回答
  •  天命终不由人
    2021-02-05 04:23

    Visual Instructions

    (based on Xcode 10.1)

    To have the path uniquely identify an asset catalog image, set the "Provides Namespace" attribute of the folder to true.

    1) Select the asset catalog folder.

    *The folder is yellow if "Provides Namespace" is false.

    2) Make sure the Inspectors panel is visible



    3) In the Inspectors panel, select the Attributes Inspector. Check the "Provides Namespace" checkbox.



    Notice that the folder icon turns blue indicating that "Provides Namespace" is true.



    When referencing the image in code, remember to include the namespace.

    let image = UIImage(named: "Icon/Menu")
    

提交回复
热议问题