iOS: How to use images in custom bundle in Interface Builder?

Van Du Tran picture Van Du Tran · Oct 12, 2011 · Viewed 15.7k times · Source

I have a bundle where i put images in it.

The contents are:

MyBundle.bundle/images/picture1.png
MyBundle.bundle/images/picture2.png

I dragged MyBundle.bundle into my project.

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.

What's wrong?

Thanks,

Answer

chown picture chown · Oct 12, 2011

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"];

I just tried this in my project and found that what you need to do is specify the image with the bundle name in front like this:

Image in IB

In the IB the image will look broken:

Broken

but when you build and run your project the image will show correctly.

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"