美文网首页
实现镂空效果+背景色

实现镂空效果+背景色

作者: 咚咚嗒大人 | 来源:发表于2021-09-16 15:40 被阅读0次

    人脸检测UI,要做一个镂空圆形,其余是黑色,但是黑色带有光圈渐变,就让ui直接出了一个背景色的图。
    具体实现如下:

    UIView *backgroundView = [[UIView alloc] init];
    backgroundView.frame = self.bounds;
         
    //背景色
    backgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    [self addSubview:backgroundView];
        
    UIImage *image = FH_IMAGE_FROM_BUNDLE(@"fh_background");
    backgroundView.layer.contents = (id) image.CGImage;
        
    // 创建一个全屏大的path
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
    // 创建一个圆形path
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x/2, self.center.y *3/2)radius:SCREEN_WIDTH/5 startAngle:0 endAngle:2 * M_PI clockwise:NO];
    [path appendPath:circlePath];
     
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = path.CGPath;
     
    backgroundView.layer.mask = shapeLayer;
    

    实现类似效果:


    image.png

    相关文章

      网友评论

          本文标题:实现镂空效果+背景色

          本文链接:https://www.haomeiwen.com/subject/dgwrgltx.html