CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:self.lineLayer.bounds];
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(self.lineLayer.frame), CGRectGetHeight(self.lineLayer.frame)/2)];
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
// 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:[UIColor blackColor].CGColor];
// 设置虚线宽度
[shapeLayer setLineWidth:CGRectGetWidth(self.lineLayer.frame)];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setLineCap:kCALineCapRound];
// 设置线宽,线间距
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:3], nil]];
// 设置路径
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL,0, (MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height))/2);
[shapeLayer setPath:path];
CGPathRelease(path);
// 把绘制好的虚线添加上来
[self.lineLayer.layer addSublayer:shapeLayer];
ios 画虚线方法
最新推荐文章于 2023-03-04 14:06:45 发布