开发者

Resources located in a separate bundle visible in IB, but not in the runtime

开发者 https://www.devze.com 2023-03-27 02:50 出处:网络
I have an application, where most of image resources are stored in the separate resource bundle (there is a valid reason to do that). This resource bundle is added to the project along with main appli

I have an application, where most of image resources are stored in the separate resource bundle (there is a valid reason to do that). This resource bundle is added to the project along with main application bundle and while I design my NIB in the Interface Builder all those images are visible inside the IB (i.e. they appear in the drop list for my UIImageView and they are properly displayed in my UI). However when I run my app in the simulator all those imag开发者_Go百科es are missing. Is there a way to tell UIKit to look for those images inside this additional resource bundle in addition to the main application bundle?

I can load those images manually in viewDidLoad no problem, but I'm looking for a way to use Interface Builder to make it easier to change design/skin of those NIBs.

Update: While image files from that bundle are available right in the drop list in the IB, they won't load in runtime. However if I prefix their names with a bundle name in IB like this:

Resources located in a separate bundle visible in IB, but not in the runtime

Then they will load properly in the runtime, but IB will display them as big blue question marks.

Now the question is - how to have best of the both worlds and have images displayed properly both in IB (design-time) and runtime.


I ran into the same problem, and it's likely due to the way that Xcode is compiling your images when assembling your bundle target. Since bundle targets aren't fully supported on iOS, you have to create them as Mac OS X targets. That leaves a problematic build setting in place, namely COMBINE_HIDPI_ARTWORK, which will be set to YES. This results in your normal and @2x variants being combined into a single tiff file in your bundle. The resulting file is supported on Mac OS but not iOS.

(Thanks to this answer for the tip).

To fix this, select your bundle-creating project in the File Navigator, select your bundle target, switch to the Build Settings tab, and search for the aforementioned setting. Then either select the whole row and tap Delete or just set it to NO.

At that point you should be able to use your images in both IB and code without doing anything special (other than making sure the .xib and image are in the same bundle).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号