[英]How to eliminate the shadow in iOS
我想创建一个ImageView对象,但是,当我使用contentRect属性创建时,结果有阴影,请帮帮我。
看这段代码:
CALayer *blueLayer = [CALayer layer];
blueLayer.frame = CGRectMake(50.0f, 50.0f, 100.0f, 200.0f);
blueLayer.backgroundColor = [UIColor blueColor].CGColor;
UIImage *image = [UIImage imageNamed:@"vclrs_me_wodeshoucang"] ;
CGImageRef imageRef = image.CGImage ;
blueLayer.contents = (__bridge id _Nullable)imageRef ;
blueLayer.contentsGravity = kCAGravityCenter ;
blueLayer.contentsRect = CGRectMake(0, 0, 2, 2) ;
blueLayer.contentsScale = image.scale ;
[self.layerView.layer addSublayer:blueLayer];
https://developer.apple.com/reference/quartzcore/calayer/1410866-contentsrect?language=objc
根据上述文件
默认为单位矩形(0.0、0.0、1.0、1.0)。
如果请求单位矩形之外的像素,则内容图像的边缘像素将向外扩展。
如果提供了一个空矩形,则结果是不确定的。
所以根据它会给出这样的输出
尝试设置self.layerView.clipsToBounds = YES
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.