方法一,使用一个UIImageView实例做子视图,并且放最后面
- - (void)setBackgroundImage {
- NSLog(@"setting bg image");
- UIImageView *customBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
- self.background = customBackground;
- [customBackground release];
-
- [self addSubview:background];
- NSLog(@"Added background subview %@", background);
- [self sendSubviewToBack:background];
- }
- (void)setBackgroundImage {
NSLog(@"setting bg image");
UIImageView *customBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
self.background = customBackground;
[customBackground release];
[self addSubview:background];
NSLog(@"Added background subview %@", background);
[self sendSubviewToBack:background];
}
方法二,Cook Book中提到的方法
- - (void)loadView {
-
- UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
- [contentView setImage:[UIImage imageNamed:@"Default.png"]];
- [contentView setUserInteractionEnabled:YES];
- self.view = contentView;
- [contentView release];
- }
- (void)loadView {
UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView setImage:[UIImage imageNamed:@"Default.png"]];
[contentView setUserInteractionEnabled:YES];
self.view = contentView;
[contentView release];
}
方法三,lvyile网友用的一个小技巧,uiView是UIView的实例,而不是UIImageView
- uiView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default.png"]];