iphoneStruggler
iphoneStruggler

Reputation: 133

Can we give some background image for any uiview?

I need to set some background image for my view. How can I do this?

Upvotes: 0

Views: 581

Answers (2)

loomer
loomer

Reputation: 2017

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

Upvotes: 5

Vladimir
Vladimir

Reputation: 170849

The simpliest way is to add an imageView to your view with appropriate background image. Just make sure that it is the lowest by z-order subview by adding it first or by calling [view sendSubviewToBack:backGroundView];

As an alternative you can set your image as a contents for your view's layer:

#import <QuartzCore/QuartzCore.h>

...    
view.layer.contents = yourImage.CGImage;

Upvotes: 1

Related Questions