tags:

views:

4181

answers:

2

This might come across as a very silly question. I am trying to place an image behind my first "Hello World" app on iphone, since this morning. I tried doing so using Interface Builder using UIImageView object from library and also tried doing so programmatically.

Googling hasn't be much of an help either. Can any one please demonstrate a simple app that shows how to display an image in an iphone app, in background and/or in foreground?

+1  A: 

You could try to add a UIImageView, in IB, to your view and arrange it to the background (behind all labels, etc)

edit: I just realized, you already tried it in IB. I was ignorant, I'm sorry. The thing is, I do this same trick myself, and it works. If you add a UIImageView to your view in IB, what happens? Does it stick to the foreground? If so, you can re-arrange the position of the object by using the 'Layout' menu.

edit2: I just searched the iphone reference library, and the "Hello World" example also shows how it is done. (http://developer.apple.com/iphone/prerelease/library/samplecode/HelloWorld/index.html)

MiRAGe
how to specify image name, through attribute inspector?, where should be the image stored? i m not able to see anything when i specify the imaage name which is in the project folder
Kazoom
you could simply drag your image (PNG, preferably) to your 'resources' folder in Xcode. Then you select your UIImageView in IB and pop up the 'Attributes inspector'. Here you can select (with a drop down) the image you just dragged to your resources folder. This is the easiest way to do it in IB.
MiRAGe
+1  A: 

The step you're missing is likely adding the image to the project.

Drag an image from the finder to the Resources section of the project outline. Xcode infers the action from the file type, and images will be copied to the Resources folder. You can check it out in the Targets section of the project outline, if you disclose your Hello World target you'll see the different build phases, including a "Copy bundle resources" build phase.

Anyway once the image is added to your project, the UIImageView inspector image name will autocomplete your image name, and all should work. No code needed.

duncanwilcox