iOS:如何在Interface Builder中使用自定义包中的图像? [英] iOS: How to use images in custom bundle in Interface Builder?
问题描述
我有一个捆绑,我将图像放入其中。
I have a bundle where i put images in it.
内容为:
MyBundle.bundle/images/picture1.png
MyBundle.bundle/images/picture2.png
我将 MyBundle.bundle
拖入我的项目。
现在我可以看到这些Interface Builder中的图像甚至可以使用它们。但是,当我运行应用程序时,我看不到图像。
Now I can see these images in Interface Builder and can even use them. However, when I run the app, I don't see the images.
出了什么问题?
谢谢,
推荐答案
确保在目标项目设置的构建阶段中复制捆绑包。
Make sure the bundle is getting copied over in the "Build Phases" of the project settings for the target.
另外,尝试以编程方式设置它们并查看它们是否显示:
Also, try setting them progrmatically and see if they show:
myImageView.image = [UIImage imageNamed:@"MyBundle.bundle/images/picture1.png"];
我刚刚在我的项目中试过这个,发现您需要做的是使用前面的包名称指定图像,如下所示:
在IB中,图像将看起来损坏:
In the IB the image will look broken:
但是当您构建并运行您的项目时,图片将正确显示。
but when you build and run your project the image will show correctly.
因此,在您的情况下,请在实际的Interface Builder图像框中使用 MyBundle.bundle / images / picture1.png
。
So, in your case, use MyBundle.bundle/images/picture1.png
in the actual Interface Builder Image box.
另外,当你没有把捆绑名称放在前面时,当你用捆绑图像加载视图时会收到这个警告:
Also, when you dont put the bundle name in front, you get this warning when you load the view with the bundle image:
2011-10-12 08:22:16.360 UTDebug[721:11c03] Could not load the "map.png" image referenced from a nib in the bundle with identifier "com.companyname.myproject"
这篇关于iOS:如何在Interface Builder中使用自定义包中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!