Search code examples
iosstatic-librariesnsbundlexcasset

Impossible to load an image in xcassets on bundle


I need to include images in a static library. I created a bundle and inserted in my images, the problem is that it seems to work if I include the images directly in the bundle, but stops working if I put in a xcassets file.

I followed many guides and searched for a solution on this site. The most popular solution is to insert this line of code:

[UIImage imageNamed:@"MyBundle.bundle/imageName"] 

but it seems not work for me

any ideas?


Solution

  • There are two ways to solve this,

    If your app is still supporting iOs 7, you can use this category: https://gist.github.com/serluca/e4f6a47ffbc19fccc63e

    Otherwise, starting from iOs 8 Apple added a way to do this using: + imageNamed:inBundle:compatibleWithTraitCollection: defined here