我可能在这里遗漏了一些明显的东西,但我一直无法解决以下问题:
我有一个包含普通和视网膜屏幕图像资源的项目,例如someimage.png和someimage@2x.png,它们存储在一个单独的包中.当我构建项目时,Xcode自动将它们打包成一个多页tiff(imageName.tiff),我在finder中检查了它 - 它实际上是两个图像的多重tiff.但是,出现了一个问题:我很难加载适当的资源.
我所做的是:
NSString * imageName = ... ;
NSLog(@"imageName: %@", imageName);
UIImage * someImage = [UIImage imageNamed: imageName];
Run Code Online (Sandbox Code Playgroud)
另外我给了辅助方法,它返回带有资源的bundle:
+(NSBundle *) resourcesBundle
{
NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"MyResourcesBundle" withExtension:@"bundle"]];
return bundle;
}
Run Code Online (Sandbox Code Playgroud)
我试过以下imageName:
imageName = [[AuxClass resourcesBundle] pathForResource:@"someimage" ofType:@"png"];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我都null对imageName.
imageName = [[AuxClass resourcesBundle] pathForResource:@"someimage" ofType:@"tiff"];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,会返回精确图像路径,但是只有在我使用imageWithContentsOfFile而不是它时它才有效imageNamed,并且它没有采用适当的资源:尽管有屏幕类型,它仍会为视网膜加载资源.
如果我省略filetype(就像我在添加@2x资源之前所做的那样,并且它工作正常,并且我尝试了第一件事并且确定它会起作用)
imageName = [NSString stringWithFormat: @"%@/%@",
@"MyResourcesBundle.bundle"",
@"someimage" ];
Run Code Online (Sandbox Code Playgroud)
什么都没有加载. …
我有一个捆绑,我把图像放在其中.
内容如下:
MyBundle.bundle/images/picture1.png
MyBundle.bundle/images/picture2.png
Run Code Online (Sandbox Code Playgroud)
我拖进MyBundle.bundle了我的项目.
现在我可以在Interface Builder中看到这些图像,甚至可以使用它们.但是,当我运行应用程序时,我看不到图像.
怎么了?
谢谢,