Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset Catalog: Access images with same name in different folders

There is an images.xcassets in my project, it contains an icons folder and two subfolders (firstFolder, secondFolder) with images. Both of my subfolders have the same number of icons and the same icons names (for different themes of my app).

So what I'm looking for: I need to get the needed icon(for current theme) from my bundle.

I've tried to do something like this:

NSBundle* bundle = [NSBundle bundleForClass:[self class]];
NSString *imageName = [bundle.bundlePath stringByAppendingPathComponent:@"icons/firstFolder/neededIcon"];

It does not work.

like image 674
Alexey Pelekh Avatar asked Oct 22 '15 15:10

Alexey Pelekh


1 Answers

Click on each folder in the assets catalog and select Provides Namespace in the Utilities View:

enter image description here

You will see that the folder then becomes blue and you can see the path to the image above the images.

You can then access the image like this:

imageView.image = UIImage(named: "folder1/Image")

or in Objective-C:

imageView.image = [UIImage imageNamed:@"folder1/Image"];
like image 93
joern Avatar answered Oct 23 '22 19:10

joern