设置UIView 背景图片二方法

来源:互联网 发布:sql 选取最大值 编辑:程序博客网 时间:2024/05/22 08:18

方法一:

UIView *theMainView  =[ [UIView  alloc] init];

UIImage *image = [UIImage imageNamed:@"bg.png"];
 UIImageView *imageView = [[UIImageView alloc] initWithImage:image] ;
 [theMainView addSubview:imageView];

方法二:

 [theMainView setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"bg.png"]]];

 

imageName 缓存,下面方法不缓存

NSString *thePath= [[NSBundle mainBundle] pathForResource:@"default" ofType:@"jpeg"]; 
UIImage *prodImg= [[UIImage alloc] initWithContentsOfFile:thePath"];  
controller
.productImg.image= prodImg;   
[prodImg release];