Van*_*ran 24 iphone bundle image interface-builder ios
我有一个捆绑,我把图像放在其中.
内容如下:
MyBundle.bundle/images/picture1.png
MyBundle.bundle/images/picture2.png
Run Code Online (Sandbox Code Playgroud)
我拖进MyBundle.bundle了我的项目.
现在我可以在Interface Builder中看到这些图像,甚至可以使用它们.但是,当我运行应用程序时,我看不到图像.
怎么了?
谢谢,
cho*_*own 39
确保在目标项目设置的"构建阶段"中复制捆绑包.
另外,尝试以编程方式设置它们,看看它们是否显示:
myImageView.image = [UIImage imageNamed:@"MyBundle.bundle/images/picture1.png"];
Run Code Online (Sandbox Code Playgroud)
我刚刚在我的项目中试过这个,发现你需要做的是在前面指定包含名称的图像,如下所示:

在IB中,图像看起来会破碎:

但是当您构建并运行项目时,图像将正确显示.
因此,在您的情况下,请MyBundle.bundle/images/picture1.png在实际的Interface Builder 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"
Run Code Online (Sandbox Code Playgroud)