ios UIBezierPath/CAShapeLayer画虚线以及圆弧

       画圆弧

        UIBezierPath * path = [[UIBezierPath alloc]init];

        [path addArcWithCenter:CGPointMake(10, 135) radius:25 startAngle:0 endAngle:2*M_PI clockwise:NO];

        

        //圆弧

        CAShapeLayer *layer1 = [CAShapeLayer layer];

        layer1.path = path.CGPath;

        layer1.lineWidth = 10;

        layer1.fillColor = [UIColor whiteColor].CGColor;

        layer1.strokeColor = [UIColor clearColor].CGColor;

        layer1.lineCap = kCALineCapRound;

        [bgVi.layer addSublayer:layer1];

        

        //虚线

       画虚线

        CAShapeLayer *shapeLayer = [CAShapeLayer layer];

        [shapeLayer setBounds:lineView.bounds];

        [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];

        [shapeLayer setFillColor:[UIColor clearColor].CGColor];

        //  设置虚线颜色为blackColor

        [shapeLayer setStrokeColor:lineColor.CGColor];

        //  设置虚线宽度

        [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];

        [shapeLayer setLineJoin:kCALineJoinRound];

        //  设置线宽,线间距

        [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];

        //  设置路径

        CGMutablePathRef path = CGPathCreateMutable();

        CGPathMoveToPoint(path, NULL, 0, 0);

        CGPathAddLineToPoint(path, NULL,CGRectGetWidth(lineView.frame), 0);

        [shapeLayer setPath:path];

        CGPathRelease(path);

        //  把绘制好的虚线添加上来

        [lineView.layer addSublayer:shapeLayer];


       主要是UIBezierpath 以及CASharpLayer的使用


你可能感兴趣的:(ios UIBezierPath/CAShapeLayer画虚线以及圆弧)