iOS [Objective-C] UIBezierPath draw circle画空心正圆

- (void)drawHollowCircle{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    CGFloat centerX = self.view.center.x;
    CGSize size = self.view.bounds.size;
    CGPoint center = self.view.center;
    CGFloat radius = 167.5;
    UIBezierPath *bezierpath = [UIBezierPath bezierPath];
    // draw circle
    [bezierpath addArcWithCenter:center
                          radius:radius
                      startAngle:0
                        endAngle:M_PI * 2
                       clockwise:YES];
    // draw mask
    [bezierpath addLineToPoint:CGPointMake(centerX, 0)];
    [bezierpath addLineToPoint:CGPointMake(0,0)];
    [bezierpath addLineToPoint:CGPointMake(0, size.height)];
    [bezierpath addLineToPoint:CGPointMake(size.width, size.height)];
    [bezierpath addLineToPoint:CGPointMake(size.width,0)];
    [bezierpath addLineToPoint:CGPointMake(centerX, 0)];
    
    bezierpath.lineWidth = 0.001;
    [bezierpath closePath];
    shapeLayer.path = bezierpath.CGPath;
    shapeLayer.fillColor = [UIColor colorWithWhite:0 alpha:0.8].CGColor;
    [self.view.layer addSublayer:shapeLayer];
}
iOS [Objective-C] UIBezierPath draw circle画空心正圆_第1张图片
Simulator Screen Shot - iPhone 8 - 2018-10-30 at 14.37.02.png

你可能感兴趣的:(iOS [Objective-C] UIBezierPath draw circle画空心正圆)