Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

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

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...