Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing image in a folder in asset catalog

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 try to name another image myImage then it will automatically get renamed to myImage-1.

But if you have two folders then you can have images with the same name in different folders.

So, there must be a way to reference these?

Does anyone know how to reference an image by the folder and image name inside the asset catalog?

like image 861
Fogmeister Avatar asked Jul 23 '14 08:07

Fogmeister


People also ask

What is a asset folder?

Assets provide a way to add arbitrary files like text, XML, HTML, fonts, music, and video in the application. If one tries to add these files as “resources“, Android will treat them into its resource system and you will be unable to get the raw data.

What does asset folder contain?

The Assets folder typically contains all Assets for creating Characters, Environments, and FX - Meshes, like Materials, Textures, Blueprints, and other source files. Level Assets are not included here.

What is an asset catalog?

An asset catalog is a type of file used to organize and manage different assets and image resolutions used by your app's user interface.

How do I create an assets folder in Xcode?

To create an additional catalog, follow these steps: Create a new file (⌘N) and select the Asset Catalog template in the iOS – Resource panel. Choose a name, select the targets that should include the catalog, and click “Create.”


1 Answers

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.

enter image description here

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

2) Make sure the Inspectors panel is visible

enter image description here

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

enter image description here

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

enter image description here

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

let image = UIImage(named: "Icon/Menu") 
like image 82
Mobile Dan Avatar answered Oct 04 '22 00:10

Mobile Dan