如何将纹理(如下所示)图像应用于不透明级别的calayer(例如结合纹理和calayer图像)?

Sample texture

最佳答案

你可以用这个

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];


您也可以尝试设置遮罩

       [self.view.layer setMask:fillLayer];

关于ios - 如何在iOS中将纹理设置为CALayer?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24984634/

10-10 20:16