Kazoom
Kazoom

Reputation: 5849

How to display background image or foreground image of an iphone app

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?

Upvotes: 0

Views: 12653

Answers (2)

duncanwilcox
duncanwilcox

Reputation: 3498

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.

Upvotes: 1

Jake
Jake

Reputation: 3973

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)

Upvotes: 1

Related Questions