iphone – 访问外部包中的图像

前端之家收集整理的这篇文章主要介绍了iphone – 访问外部包中的图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个名为applausible.bundle的软件包,我将软件包放在支持文件中.这是我的代码

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

在这里,我无法在图像视图上显示图像.我尝试的另一种方法是在运行应用程序时使用xib将图像放在图像视图上.输出在控制台中就像这样
无法加载标识符为“com.xxxxxxx.ImageSample”的包中从nib引用的“splash_screen high resolution.png”图像.任何人都可以告诉我我在哪里犯了错误.最后我的目标是在外部捆绑的UIImageview上显示图像.

解决方法

这可能对你有所帮助.

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];

请试一试.

猜你在找的Xcode相关文章