如何将纹理(如下所示)图像应用于具有不透明度级别的 calayer,例如组合纹理和 calayer 图像?
最佳答案
你可以用这个
UIImage *yourImage = [UIImage imageNamed:@"yourTextureImage"];
self.yourView.layer.contents = (__bridge id) yourImage.CGImage;
编辑尝试在现有层上添加子层。它会让您知道如何做到这一点。
//It will draw some circle
int radius = 30.0;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 20.0, 20.0) cornerRadius:0];
UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius];
[path appendPath:circlePath];
[path setUsesEvenOddFillRule:YES];
CAShapeLayer *fillLayer = [CAShapeLayer layer];
fillLayer.path = path.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = [UIColor blackColor].CGColor;
fillLayer.opacity = 0.7;
[self.view.layer addSublayer:fillLayer];
你也可以尝试设置 mask
[self.view.layer setMask:fillLayer];
关于ios - 如何在 ios 中将纹理设置为 CALayer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24984634/