UIview定义背景图片

    UIImage *image = [UIImage imageNamed:@"bgimagename"];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 100)];
    //view.backgroundColor = [UIColor colorWithPatternImage:image]; //这种是正常的图片转成背景色
    view.layer.contents = (id)image.CGImage;//这种的比较好,可支持半透明,兼容性又好。
    [self.view addSubview:view];

原文地址:https://www.cnblogs.com/lear/p/3213975.html