UIView设置图片(更轻量级,可替代UIImageView)

2016-09-22  本文已影响36人  InitWithYou
    UIView *yourView = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 220,220)];
    [self.view addSubview:yourView];
    UIImage *image = [UIImage imageNamed:@"018.png"];
    yourView.layer.contents = (__bridge id)image.CGImage;
    // 设置显示的图片范围
//    yourView.layer.contentsCenter = CGRectMake(0.25,0.25,0.5,0.5);//四个值在0-1之间,对应的为x,y,width,height。
上一篇下一篇

猜你喜欢

热点阅读