ios - 如何在 ios 中将纹理设置为 CALayer?

标签 ios calayer

如何将纹理(如下所示)图像应用于具有不透明度级别的 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];

你也可以尝试设置 mask

       [self.view.layer setMask:fillLayer];

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

相关文章:

iphone - 在 3D 中包裹/扭曲 CALayer/UIView(或 OpenGL)(iPhone)

ios - 如何在 IOS 中修整可调整大小的 UIView 的一个角?

ios - 在 UIView 周围绘制 CALayer 边框

ios - 如何将 UILabel 放在 SKSpriteNode 后面

ios - 使用 GooglePlus 类从 NSDictionary 获取键值

ios - token 被撤销后 Google SignIn 崩溃

iphone - 带虚线的 UIView

ios - CoreData 到 Realm 迁移和 Realm 内部迁移作为单独的步骤

iphone - iPhone/iOS 上的通用 LISP

iphone - 我不知道为什么我的观点卡住