Image not showing in iPhone Simulator
I dragg开发者_开发技巧ed an image from the Media Library in my Interface Builder and can see the image in my xib. However, when I open up the iPhone Simulator the image isn't there. Do I need to put code into the program's .m or .h to be able to show the image I have on IB?
You need to add the Image to the "Resources" Folder in your Application Directory, so that the Image can be copied to your target "Copy Bundle Resources", this folder contains all the resources your application is using. Otherwise when the iPhone Simulator runs it will not find the image
In order to add an Image to the Resources ctrl+click the folder and select add..-> existing files, then select your image and click Add.
Hope that is clear.
-Oscar
I have had this and this point came to light when images from one designer worked fine but from another not. If it is a PNG then make sure it has been saved/exported with "interlaced" turned ON / ticked or whatever, this worked for me.
It is very strange it appears in the Interface Builder but in the simulator it is absent!
Well I never used IB that much for that to understand what you're doing.
But, the steps that I used to take is:
Make sure the image resources path is correct, and it's local to the project, not referenced from an unknown path.
Make sure it's shown in UIImageView inspector in the IB.
Select the image name inside the inspector.
Make sure the image is displayed in the UIImageView placeholder.
If things go wrong with IB, I'd rather write code, initialize UIImageView instance at the right position. It's less headache for debugging.
If by 'opening the Simulator' you mean that you select Simulate Interface from Interface Builder's File menu, then yes, that will not work.
To run your application in the simulator you will have to hit the Build and Run button in Xcode.
Is the "hidden" box checked in IB? Or maybe in your code or in IB you set alpha to zero? Just to make sure, connect the image in IB to your code in the .h file, and in your .m type this in your viewDidLoad:
function:
image.alpha = 1;
image.hidden = NO;
Try this and tell me if it works!
Image can be any where in application folder as long it's included in project, when you select particular image from left pane , in right pane under "Target Membership" check if check-box is checked for target
The problem could also be related to a problem or inconsistency with the images format as Recycled Steel pointed out.
In my particular case, I dragged .JPG
files into my Images.xcassets
and used those.
It turns out these images rendered correctly in my Storyboards, but were not displayed on the emulator.
To fix this, I converted the .jpg
to .png
files (with GIMP/Photoshop or any other image processing software) and now it works both on the storyboard and on the emulator.
IMAGE MUST BE ADDED TO THE CORRECT TARGET!
When adding the image you need to add it to the target that you need. Whether it's a custom keyboard or something else.
Silly solution but at times one could forget!
精彩评论