CAShapeLayer 做为mask时,如何修改CAShapeLayer的边框颜色?   


path 是一个UIBezierPath,是一个多边形,
我需要显示多边形内部的东西,其余舍弃,
但我把shapeLayer作为UIImageView.layer的mask时,我设置的shapeLayer的颜色不起作用,是哪出了问题,


          CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
         
 
               
          shapeLayer = [CAShapeLayer layer]; 
         
 
               
          shapeLayer.path           = path.CGPath; 
         
 
               
          shapeLayer.strokeColor    = [UIColor redColor].CGColor; 
         
 
               
          shapeLayer.borderColor    = [UIColor redColor].CGColor; 
         
 
               
          shapeLayer.lineWidth      = 2; 
         
 
               
          imageView.layer.mask = shapeLayer; 
         
 
          iOS 的mask layer 层: 
         
 
          mask是个遮罩,只有透明度信息有用,颜色信息是被忽略的,你设置它的颜色没有意义,不知道您是想实现什么功能?
您如果一定要一个边框,也可以这么做试试看

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer = [CAShapeLayer layer];
    shapeLayer.path           = path.CGPath;
CAShapeLayer *borderLayer=[CAShapeLayer layer];
    borderLayer.path    =   path.CGPath;
    borderLayer.fillColor  = [UIColor clearColor].CGColor;
    borderLayer.strokeColor    = [UIColor redColor].CGColor;
    borderLayer.lineWidth      = 2;
    borderLayer.frame=imageView.bounds;

    imageView.layer.mask = shapeLayer;
    [imageView.layer addSublayer:borderLayer];
 
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6