美文网首页
iOS [Objective-C] UIBezierPath d

iOS [Objective-C] UIBezierPath d

作者: 巴糖 | 来源:发表于2018-10-30 14:37 被阅读11次
    - (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];
    }
    
    Simulator Screen Shot - iPhone 8 - 2018-10-30 at 14.37.02.png

    相关文章

      网友评论

          本文标题:iOS [Objective-C] UIBezierPath d

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