Image not showing in UIImageView in Interface Builder / iPhone

43,030

Solution 1

Try cleaning and rebuilding the project.

If it's still not working then remove all images from Xcode (select delete reference only) and then re-add them again by dragging those images into Xcode. Then re-build it and it should work.

Solution 2

My recipé: CLEAN + Build + QUIT XCODE AND THEN REOPEN IT!

Voilá!! It's there!

Solution 3

Make sure you have added your image to target when dragging it into the project. Because Xcode's folder / group / project system is buggy, click on the image and check that it is actually added to the target build in the inspector as shown (a graphical problem deserves a graphic answer!) :

Add the image to the project...

enter image description here

Add to targets... (or so we think)

enter image description here

Background image shows nicely in Interface Builder...

enter image description here

But when we run, we have nothing but the background color we set... no image...

enter image description here

Clicking on the UIImageView in Interface Builder and using the inspector, we scroll down and find that in fact it was never added to the target like Xcode clearly showed in step 2...

enter image description here

So we add it to the target...

enter image description here

And we build and run and voila! Our image shows in the UIImageView exactly where it is suppose to show.

enter image description here

This drove me nuts for the better part of the day until I tried adding code to make it happen to see if it was a flakey image. I added it without issue by creating the the viewDidLoad implementation below.

Note that you don't need this if Xcode / Interface Builder is working the way it should. Either user IB or use this code, not both :

- (void)viewDidLoad {
UIColor *   theColor;
UIImage *   theImage;

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
theImage = [UIImage imageNamed:@"/<redacted>/background sea green gradent.png"];
theColor = [UIColor colorWithPatternImage: theImage ];
[self.view setBackgroundColor: theColor ]; }

Note: This can be the same issue if your button is not showing a custom image...

Solution 4

Just ran into this issue. Exported the identical images in Adobe Illustrator. One as transparent, the other as white. The transparent one showed up with a big blue question mark. Running it, worked fine however. Something to do with IB and transparent PNGs

Solution 5

just for the record (because nothing worked for me):

We only had retina-graphics in our projects. After update to XCode 5 all images had a white question mark in it (only in the Interface Builder, not in Simulator). We switched the image source to non-retina, which solved the case!

enter image description here

Using btn-category-6.jpg solved the issue!

Share:
43,030
dbonneville
Author by

dbonneville

Graphic Designer / Developer

Updated on September 10, 2020

Comments

  • dbonneville
    dbonneville over 3 years

    I have a UIView with an UIImageView dragged onto the view. All of a sudden, for all my xibs, the image no longer shows up. There is a blue X. However, when it builds, the image is there.

    At one point, I deleted and regenerated all my images and moved some into a subfolder in Xcode. Normally, when you go to select an image for an UIImageView, IB allows you to pick from any image in the project. But, I can't see any of the images I had put in the folder anymore in the dropdown.

    All I see in the dropdown on the Inspector is the one image I want, but that is also the one that is not showing up. And like I said, if I build it on the device or simulator, it all works.

    There is some cache or something screwed up somewhere. Everything builds with no errors. I cleared the caches and rebuilt. It all works. No error or warnings. But...I can't see any other images and IB still thinks it's missing the image that is clearly selected in the dropdown.

    So how do I get Xcode and IB back on track and see what assets it properly should be seeing in the XIBs?