//绘制虚线
- (void)drawDashLine {
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:self.bounds];
[shapeLayer setPosition:self.center];
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
[shapeLayer setStrokeColor:[UIColor redColor].CGColor];
[shapeLayer setLineWidth:1.5f];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setLineDashPattern:@[@6, @3]];
//设置绘制的路径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(self.frame.size.width, 0)];
[shapeLayer setPath:path.CGPath];
[self.layer addSublayer:shapeLayer];
}
iOS学习- OC绘制虚线
最新推荐文章于 2024-08-13 17:28:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)