xcode Interface Builder 没有显示我的一些资源图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1788628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Interface Builder doesn't show some of my resource images
提问by Burcu Dogan
I have almost 20 images in PNG format added to my current project on Xcode (under the proper group, Resources). Unfortunately, library window's Media tab doesn't show some of them. And if I create an UIImageView and set one of these invisible images from code, nothing shows up. I also tried from IB with adding a UIImageView and set its source image.
我在 Xcode 上的当前项目中添加了近 20 张 PNG 格式的图像(在适当的组资源下)。不幸的是,库窗口的媒体选项卡没有显示其中的一些。如果我创建一个 UIImageView 并从代码中设置这些不可见图像之一,则不会显示任何内容。我还尝试从 IB 添加 UIImageView 并设置其源图像。
Is this problem a image format related issue or is there a tiny detail I'm missing.
这个问题是与图像格式相关的问题还是我遗漏了一个小细节。
What log says:
什么日志说:
Could not load the "07_clock_icon.png" image referenced from a nib in the bundle
回答by Robin
The solution to this is a bit silly, but it definitely works:
对此的解决方案有点愚蠢,但它绝对有效:
Close XCode and the Interface Builder. Now, instead of opening XCode then opening the project, navigate to the project in Finder and double click on the project. When you open your xib file the blue file not found images will flash up, then be replaced with the correct images and the dropdown will show all your images in the Inspector.
关闭 XCode 和 Interface Builder。现在,不是打开 XCode 然后打开项目,而是在 Finder 中导航到该项目并双击该项目。当您打开您的 xib 文件时,蓝色文件未找到图像将闪烁,然后替换为正确的图像,下拉列表将在检查器中显示您的所有图像。
回答by Victor Alexander
Heyy! I figured it out. It's a refreshing bug. So just copy and replace those images that did not load into your project folder, and then hold Shift Command K (to clean your project). After Clean Up it should work perfectly! Enjoy!
嘿!我想到了。这是一个令人耳目一新的错误。因此,只需复制并替换那些未加载到项目文件夹中的图像,然后按住 Shift Command K(清理项目)。清理后它应该可以正常工作!享受!
回答by Rupesh R Menon
Same problem was encountered by me. The problem is with the image. The image has been some how corrupted.Try to open the image in photoshop and you will see it doesn't open with photoshop. I solved the problem by changing the image format to PNG-24and everything works fine for me. Hope this will solve your issue.
我也遇到了同样的问题。问题出在图像上。图像已损坏。尝试在 photoshop 中打开图像,您会看到它无法用 photoshop 打开。我通过将图像格式更改为PNG-24解决了这个问题 ,一切对我来说都很好。希望这能解决您的问题。
Regards,
问候,
Rupesh R Menon
鲁佩什·梅农
回答by mensch
If you dragged the images from the Finder into the Resources folder in XCode the images should show up in IB as well. At least it does so in my setup.
如果您将图像从 Finder 拖到 XCode 的 Resources 文件夹中,图像也应该显示在 IB 中。至少在我的设置中是这样的。
Maybe the images are 8-bit PNG images. I believe Cocoa requires them to be 24-bit because of the alpha transparency. PNG 8-bit doesn't support the alpha channel, as it's more like a GIF image.
也许图像是 8 位 PNG 图像。我相信 Cocoa 要求它们是 24 位的,因为 alpha 透明度。PNG 8 位不支持 alpha 通道,因为它更像是 GIF 图像。
But from the error you posted It seems IB couldn't find the resource at all. Which is understandable if it doesn't load the resources from XCode in its library.
但是从您发布的错误看来,IB 根本找不到资源。如果它不从其库中的 XCode 加载资源,这是可以理解的。
回答by Meltemi
Assuming you selected the option to let XCode copy the files into your project and neither XCode nor the Finder complain when you make the copy... I wonder if there might be some file corruption? Maybe try recreating them or opening and resaving them from another graphics application (or even Preview.app).
假设您选择了让 XCode 将文件复制到您的项目中的选项,并且在您进行复制时 XCode 和 Finder 都没有抱怨......我想知道是否可能存在某些文件损坏?也许尝试重新创建它们或从另一个图形应用程序(甚至 Preview.app)打开并重新保存它们。
btw- 8-bit PNGs have worked fine for me.
顺便说一句- 8 位 PNG 对我来说效果很好。