本文介绍了如何在iOS中将纹理设置为CALayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将纹理(如下所示)图像应用于具有不透明度级别(如结合纹理和calayer图像)的calayer?
>
您可以使用此
UIImage * yourImage = [UIImage imageNamed:@ yourTextureImage];
self.yourView.layer.contents =(__bridge id)yourImage.CGImage;
编辑尝试在现有层上添加此子层。
//它将绘制一些圆
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];
[路径appendPath:circlePath];
[路径setUsesEvenOddFillRule:YES];
CAShapeLayer * fillLayer = [CAShapeLayer层];
fillLayer.path = path.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = [UIColor blackColor] .CGColor;
fillLayer.opacity = 0.7;
[self.view.layer addSublayer:fillLayer];
您也可以尝试设置遮罩
[self.view.layer setMask:fillLayer];
How texture(like below) image can be applied to calayer with opacity levels like combining texture and calayer image?
解决方案
You can use this
UIImage *yourImage = [UIImage imageNamed:@"yourTextureImage"];
self.yourView.layer.contents = (__bridge id) yourImage.CGImage;
EDIT Try this add sublayer on existing layer.It will give you idea how to do that.
//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];
You can also try setting mask
[self.view.layer setMask:fillLayer];
这篇关于如何在iOS中将纹理设置为CALayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!