Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset Catalogs in resource bundles

Tags:

I have a separate bundle of resources that ship with my framework. I want to put and use an asset catalog in that bundle. However UIImage imageNamed: says it uses the current apps main bundle. How do I load an image from an asset catalog in a different bundle?

The trick of using [bundle pathForResource:name ofType:@"png"] doesn't work with the compiled asset catalog. I have verified that the Assets.car file is indeed in the bundle and it contains my images.

like image 937
GilroyKilroy Avatar asked Sep 19 '13 17:09

GilroyKilroy


People also ask

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 add an asset catalog in Xcode?

Choose File > New > File. Choose Resource > Asset Catalog, and click Next. Give the asset catalog a name, choose a location, and click Create.

What is asset catalog Xcode?

An asset catalog, simply put, is a single folder in Xcode that you use to organize your app's images, icons, colors, and more. Instead of adding individual images to Xcode's file organizer, you add assets neatly organized in a single catalog.


1 Answers

As of iOS 8, you can now use [UIImage imageNamed:inBundle:compatibleWithTraitCollection:] to load images by name from a different bundle. For example, a dynamic framework can use its own asset catalog separate from the main app's bundle.

like image 83
Wombat Avatar answered Sep 19 '22 18:09

Wombat