方法一,使用一个UIImageView实例做子视图,并且放最后面
方法二,Cook Book中提到的方法
方法三,lvyile网友用的一个小技巧,uiView是UIView的实例,而不是UIImageView
Objective-c代码
- -
(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中提到的方法
Objective-c代码
- -
(void)loadView { -
-
UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; -
[contentView setImage:[UIImage imageNamed:@"Default.png"]]; -
[contentView setUserInteractionEnable d:YES]; -
self.view = contentView; -
[contentView release]; - }
方法三,lvyile网友用的一个小技巧,uiView是UIView的实例,而不是UIImageView
Objective-c代码
- uiView.backgroundColor
= [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default.png"]];