How to properly insert a background image
I use this code to set a background image. The only problem is that it covers everything I insert in the XIB file. What should I do to ensure that my textfields, buttons, etc. are also visible (in front of the backgr开发者_StackOverflowound). Thanks for your help!
// Setup the background
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.view addSubview:background];
[background release];
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]]; [self.view addSubview:background]; [self sendSubviewToBack:background]; [background release];
If you are using an XIB, then just make sure that all of your objects are above the UIImageView
.
Alternatively, you can use colorWithPatternImage:
UIImage * bg = [UIImage imageNamed:@"bg.png"];
[myView_ setBackgroundColor:[UIColor colorWithPatternImage: bg]];
精彩评论