Home > OS >  How to load UIImage from folder in assets library
How to load UIImage from folder in assets library

Time:01-20

I am trying to load an image from my XCode assets library:

enter image description here

Using this code:

[self.imgIcon setImage[UIImage imageNamed:@"symptoms/anxious.buz"]];

It works if I don't have the asset in a folder in the assets library. I've also tried renaming it to .png, as well as using 'symptoms.anxious.buz'. Because it works without a folder, I suspect there is some special way to form the path to indicate you want to look inside a folder.

What is the proper grammar for loading an asset from inside a folder of the assets library?

CodePudding user response:

If you want the name of the folder to be part of the image name then you need to tick the Provides Namespace option on the folder in the asset catalog...

enter image description here

Otherwise you can just use the asset name without the folder. So in your case...

[UIImage imageNamed:@"anxious.buz"]
  • Related