Putting .xib files in a resource bundle with images

654 views Asked by At

I am building a ResourceBundle which contains .xib and .storyboard files. These are files that are accessed by a static library that I built. The reason they are in a bundle is because the static library is used from multiple apps.

These storyboard and .xib reference a number of images which are part of an Asset catalog. The dilemma is where should the asset catalog be.

If I put the asset catalog in the bundle along with the .xib files, iOS7 cannot load any of the images. That's because [UIImage imageNamed:] only looks at the main bundle in iOS7.

Instead if I put the catalog in the app then the images load correctly in iOS7, but fail to load in iOS8! I could put the asset catalog both in the bundle and in the main app and then it works for both iOS7 & 8. However, this doubles the size of the image data I am shipping with the app.

Another option that worked for me was to set the min deployment version of the bundle to IOS6. This prevents the Asset Catalog from being compiled to Assets.car and the image can be loaded from both iOS 7 and 8. This approach worked for one my ResourceBundles, but for the other one it did not create different files for my iPhone and iPad images.

Thoughts on how I could resolve this?

1

There are 1 answers

2
Constantin Saulenco On

I had the same issue , with framework and bundle, the only solution that helped me is that I add the images directly to bundle folder, and of curse add them to Copy Bundle Resources not in the asset catalog , and it works fine:

first get your bundle:

NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"YourBundle" ofType:@"bundle"]];

then get your image:

NSString *imagePath = [bundle pathForResource:@"imageName" ofType:@"imageType"];
UIImage* yourImage = [UIImage imageWithContentsOfFile:imagePath];

hope it will help.