我创建了一个名为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];
请试一试.