图层路径加减法

        UIBezierPath *path       = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        UIBezierPath *path1 =[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(self.dottedLine.origin.x+1,
                                                                                self.dottedLine.origin.y+1,
                                                                                self.dottedLine.width-2,
                                                                                self.dottedLine.height-2)]bezierPathByReversingPath];

        [path appendPath:path1];

        CAShapeLayer *shapeLayer = [CAShapeLayer layer];

        shapeLayer.path          = path.CGPath;

        [self.layer setMask:shapeLayer];

推荐阅读更多精彩内容