EvGeniy Ilyin
EvGeniy Ilyin

Reputation: 1919

How to get image from assets by folder ios

I heve Assets catalog like this

how i can get image depend of component (folder) ? I like to use something what it is

let image = UIImage(named:"ComponentA/Background")

but this doesn't work

Upvotes: 3

Views: 4164

Answers (2)

Saif
Saif

Reputation: 2958

you can get image depending on folder by "Providing Namespace" to folder.

  1. Select folder in .xcassets
  2. Check "Providing Namespace" in last tab (see attached image)
  3. Access image using var image : UIImage = UIImage(named:"New Folder/bgimg")

enter image description here

Upvotes: 5

Suhas Arvind Patil
Suhas Arvind Patil

Reputation: 1750

folders are for our reference only

you need to provide different names, and use only image names in programming.

Upvotes: 1

Related Questions