开发者

Image not showing in UIImageView in Interface Builder / iPhone

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. The开发者_开发知识库re 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?


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.


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

Voilá!! It's there!


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...

Image not showing in UIImageView in Interface Builder / iPhone

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

Image not showing in UIImageView in Interface Builder / iPhone

Background image shows nicely in Interface Builder...

Image not showing in UIImageView in Interface Builder / iPhone

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

Image not showing in UIImageView in Interface Builder / iPhone

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...

Image not showing in UIImageView in Interface Builder / iPhone

So we add it to the target...

Image not showing in UIImageView in Interface Builder / iPhone

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

Image not showing in UIImageView in Interface Builder / iPhone

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...


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


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!

Image not showing in UIImageView in Interface Builder / iPhone

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


For me it was because the images had a ".png" in attributes inspector. Removing it fixed the issue


Just an FYI: I had a similar problem. At some point the images were corrupted and they were all Transparent PNGs!

I replaced the files and now they are showing again. The image corruption may have happened when I copied the files via Windows Explorer in Oracle's Virtual Box running Windows XP.


In my case when I have created new project in Xcode 6 I can not show the images in the Simulator and as well as in device. I have imported all the images in the image assets making a folder within that.Now I have imported all the images, all are working fine now. All images are now showing now.

Follow these steps:

STEP 1:

Image not showing in UIImageView in Interface Builder / iPhone

STEP 2:

Image not showing in UIImageView in Interface Builder / iPhone

STEP 3:

Image not showing in UIImageView in Interface Builder / iPhone

and then Import images which you need. Reference Link: StackOverflow link


For me the problem was, I could see the new added image files on Show the media library but not in the dropdown for my button Image

For me the solution was, typing the name manually. When I started typing the image names in the text box, it autocompleted it and that's it. |

PS: I also implemented the selected solution before doing so

Image not showing in UIImageView in Interface Builder / iPhone


I had the same symptoms, but I just moved the project folder to the desktop, re-ran the project in IB from there and it worked! Then work it back into the same parent folder again, with a different name...strange.


I had this problem several times. And copying the project directory to the desktop, renaming the original folder, opening the project from the new location and moving it to the original directory again helped every time. All those "Load all header files" solutions sometimes work and sometimes don´t


This happened when I moved the images to xcassets. I solved it by removing png and jpg extensions on inspector.


The .png was missing from the end of my image name in attributes inspector

After cleaning, re-importing and checking the assets where mapped correctly, nothing worked, though I found my image (which is a png) showed up once I entered .png at the end of the image name in the attributes panel.

Image not showing in UIImageView in Interface Builder / iPhone


Make sure you have an asset matching the image scale that matches the screen size you are viewing in your Interface Builder file in Xcode. There are @1x, @2x, and @3x spots for image assets if you're using the asset catalog in Xcode, or, if you're not using it, then you should have different assets differentiated by their file name (e.g. "image.png, image@2x.png, image@3x.png).

You may not have multiple asset sizes and just have provided one asset for say 1x or 3x and you may be viewing the screen in Interface Builder for a device type that uses a different asset size and thus the UIImageView's image won't render in Xcode. For example, I was viewing the interface for an iPhone 7, which uses 2x, but the asset only had a 3x version. When I added a 2x version it immediately showed up in the Interface Builder in Xcode.

Note that even if it doesn't render in Xcode, it may still render properly at runtime. Still, it's good practice to provide assets at resolutions that will be appropriate for each device model.


Make sure you're referencing an image asset that actually exists. I had added my files to the Xcode Asset Catalog (.xcassets) as usual, but forgot to rename from the default name of "Image" to the name I was using in the storyboard.


If you have all of the 1x, 2x, and 3x images set, cleaned and built the project and it still doesn't show up correctly, exit Xcode and force quit, then open Xcode again. Just a simple Xcode restart worked for me.


I've ran across this problem a few times - sometimes (I'm not too sure why...), Xcode seems to forget the link between a UIImageView and the image in your folder.

It may then be as simple as going to the attributes inspector for that image view, and if the image box says 'Unknown image', re-selecting the correct image!

Image not showing in UIImageView in Interface Builder / iPhone


If none of these answers work, one possible reason could be: If you are using a UIButton and displaying an image in it, make sure that button does not have a title. It will show an ellipse (...) because the button caption is being truncated.


For me, I just need to click on my assets and view the images there briefly. Then I return to the storyboard and the images are populated.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜