tips

界面上画一个半透明黑色蒙版,想让某个位置有一个透明的形状,可以用在『使用提示』、『头像选取』、『扫描二维码』上。

      // 圆形框的直径
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    CGContextSaveGState(contextRef);
    CGContextSetRGBFillColor(contextRef, 0, 0, 0, 0.5);
    CGContextSetLineWidth(contextRef, 3);
    
    // 创建圆形框UIBezierPath:
    UIBezierPath *pickingFieldPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 100, 100, 100)];
    
    // 创建外围大方框UIBezierPath:
    UIBezierPath *bezierPathRect = [UIBezierPath bezierPathWithRect:rect];
    
    // 将圆形框path添加到大方框path上去,以便下面用奇偶填充法则进行区域填充:
    [bezierPathRect appendPath:pickingFieldPath];
    
    // 填充使用奇偶法则
    bezierPathRect.usesEvenOddFillRule = YES;
    [bezierPathRect fill];
    
    CGContextRestoreGState(contextRef);
    self.layer.contentsGravity = kCAGravityCenter;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容