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

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

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

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

    beijingimage.frame = self.view.frame;it

   [self.view addSubview:beijingimage];io

 

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

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

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

    [image drawAsPatternInRect:self.view.bounds];view

 

 

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

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

 

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

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

相关文章
相关标签/搜索