views:

61

answers:

2

How do I set the background image of my UIViewController? What is the code to do it? Right now I have

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.jpg"]];

but I don't want a pattern. I want it to fill the screen properly.

Thanks!

+1  A: 

you could use:

UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Blah.png"]];

[self.view addSubview:backgroundImage];
[self.view sendSubviewToBack:backgroundImage];

Apple HD image Guide

Jesse Naugher
The iPhone 4 is 960-by-640-pixel resolution at 326 ppi according to Apple's website. When I make an image this large, it is way too big for a background when i try putting it on my phone using that code. How do I make it fit? I'm trying to make a high resolution background for one of my applications.
Robert Eisinger
ahh. I would try reading up on the point to pixel conversion (there is a guideline to this somewhere). I personally am not exactly sure how it works, but you would just have to adjust the UIImageViews frame perhaps? I personally have never used the HD resolution for iPhone4.
Jesse Naugher
What do you mean "points to pixel" conversion? Would you mind helping me find some guide on this?
Robert Eisinger
added a link in my answer to the apple guide on supporting HD images.
Jesse Naugher
thank you kindly.
Robert Eisinger
A: 

To expand on Jesse Naugher's code: UIView (or UIViewController, for that matter), holds no built-in way of using an image for background. What you have to do is to use a UIImageView, which is a UIView subclass specifically for displaying images, and add that to the back of your view hierarchy.

eliego
Thank you. I understand. Do you have any wisdom on the matter that I posted as a comment to Jesse Naugher's code?
Robert Eisinger