Not My Name Car
Not My Name Car

Reputation: 59

iOS Background Image doesn't display properly?

I've literally piled through hundreds go searches on google :(. I can't seem to figure out what I'm doing wrong when I create an image in photoshop (960 x 600, -40 for the status bar). The image comes out to this:

When it should look like this:

(note this is not the actually size, crappy thumbnail version :P. The size is as stated above)

This is my code:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"MenuBkground.png"]];

Am I doing something wrong when I make the image? Is it in the code? Any ideas?

Upvotes: 1

Views: 402

Answers (2)

JSA986
JSA986

Reputation: 5936

Another way if your using interface builder,

  1. Drag an image view to your viewController.

  2. Assign that as MenuBkground.png in the inspector (first drop down box)

Upvotes: 2

Max
Max

Reputation: 6229

You're using colorWithPatternImage which basically means what it says. The image will repeat itself if the space is not entirely consumed by the image. If you want to have a true background image you should create the image as a subview.

UIImage* image = [UIImage imageNamed:@"MenuBKground.png"];
UIImageView* background = [[UIImageView alloc]initWithImage: image];
[self.view addSubview: background];

Upvotes: 3

Related Questions