系统有提供方法创建一个虚线
//虚线圆
CAShapeLayer *layer = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:self.view.center radius:90 startAngle:0 endAngle:M_PI * 2 clockwise:YES];layer.path = path.CGPath;
layer.strokeColor = [UIColor greenColor].CGColor;
layer.fillColor = [UIColor clearColor].CGColor;
layer.lineWidth = 10;
//重新计算开始 结束 位置
// layer.strokeEnd = 0.8f;
// layer.strokeStart = 0;
//设置虚线 第一个数组 虚线每格的大小 第二个 每格之间的间距
[layer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:5],
[NSNumber numberWithInt:2], nil]];
[self.view.layer addSublayer:layer];
//虚线
CAShapeLayer *lineLayer = [CAShapeLayer layer];
CGMutablePathRef linePath = CGPathCreateMutable();
//设置虚线颜色
[lineLayer setStrokeColor:[[UIColor redColor] CGColor]];
//设置填充颜色颜色
[lineLayer setFillColor:[[UIColor clearColor] CGColor]];
//设置虚线宽度
lineLayer.lineWidth = 2.0f ;
//线的宽度 每条线的间距
NSArray *linePathArr = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5], nil];
[lineLayer setLineDashPattern:linePathArr];
CGPathMoveToPoint(linePath, NULL, 100 ,150);
CGPathAddLineToPoint(linePath, NULL, 200, 150);
CGPathAddLineToPoint(linePath, NULL, 230, 250);
[lineLayer setPath:linePath];
CGPathRelease(linePath);
//虚线添加
[self.view.layer addSublayer:lineLayer];