设置一个View的背景图片的集中方法

控制器view的背景图片的方法, 四种:

1.直接在控制器view上添加一个imageView大小设置的和view一样

    UIImageView *beijingimage = [UIImageView alloc]initWithImage:[UIImage imageNamed:@"beijing"];

    beijingimage.frame = self.view.frame;

   [self.view addSubview:beijingimage];

 

2.重写控制器view, 直接drawRect画在上面

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);

    UIImage * image = [UIImage imageNamed:@"beijing"];

    [image drawAsPatternInRect:self.view.bounds];

 

 

3.把image转换成UIColor对象, 再通过设置背景颜色设置

    self.view.backgroundColor = [UIColor colorWithPatternImage:@"beijing"];

 

4.设置layer.contents, 直接设置图片内容

self.view.layer.contents =[UIImage imageNamed:@"beijing"];

posted @ 2015-09-27 00:54  王刚韧(wanghy_iOS)  阅读(539)  评论(0编辑  收藏  举报