Access to the image in the external kit

I created a package called applausible.bundle, I put the package in the support files. This is my code.

NSBundle* myBundle; myBundle = [NSBundle bundleWithPath:@"/Library/applausible.bundle"]; NSString *path = [myBundle pathForResource:@"splash.png" ofType:nil]; [imageName setImage:[UIImage imageNamed:path]]; 

Here I can not display the image on the image. Another way I tried this is I place the image on the image using xib during application startup. The output is the same as in the console. The image "splash_screen high resolution.png" could not be loaded, which is referenced by the thread with the identifier "com.xxxxxxx.ImageSample". Can someone tell me where I made a mistake. Finally, my goal is to display an image on a UIImageview , which is in an external bundle.

+4
source share
2 answers

This can help you.

  NSString bundlePath = [[NSBundle mainBundle] pathForResource:@"applausible" ofType:@"Bundle"]; NSLog(@"Bundle path is %@",bundlePath); NSBundle myBundle; myBundle = [NSBundle bundleWithPath:bundlePath]; NSString *path = [myBundle pathForResource:@"splash_screen high resolution" ofType:@"png"]; UIImage *image=[[UIImage alloc]initWithContentsOfFile:path]; [imageName setImage:image]; 

try it.

+6
source

It may be useful.

 NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"applausible" ofType:@"Bundle"]; 

using this method, you can get the package path. Then use your code from the second line

 myBundle = [NSBundle bundleWithPath:bundlePath]; NSString *path = [myBundle pathForResource:@"splash" ofType: n@ "png"]; [imageName setImage:[UIImage imageNamed:path]]; 
0
source

Source: https://habr.com/ru/post/1401104/


All Articles