Alex Rivera | Logout

Load image from bundle with iOS

Asked 2011-04-14T14:29:40.887
70

I added to my project a .bundle folder filled with some images. Is it correct refer to this image directly writing something like ?:

[UIImage imageNamed:@"imageInBundle.png"];

Which is the best method to access and use these images ?

Edit
Report

1 Answer

26

1) If you are working with bundles go to bundle target and set COMBINE_HIDPI_IMAGES to NO. In another case the image will be converted to tiff format.

2) try this code:

NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"YourBundle" withExtension:@"bundle"]];
NSString *imagePath = [bundle pathForResource:@"imageInBundle" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
answered 2013-07-15T13:46:54.653

Your Answer