Ios 如何使用UIBezierPath绘制各种类型的线
我正在用UIBezierPath画一条线Ios 如何使用UIBezierPath绘制各种类型的线,ios,objective-c,uibezierpath,Ios,Objective C,Uibezierpath,我正在用UIBezierPath画一条线 [path moveToPoint:CGPointMake(xco2, yco2)]; [path addLineToPoint:CGPointMake(xco, yco)]; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [path CGPath]; shapeLayer.strokeColor = [[UIColor whiteColor] CGColor];
[path moveToPoint:CGPointMake(xco2, yco2)];
[path addLineToPoint:CGPointMake(xco, yco)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor whiteColor] CGColor];
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor clearColor] CGColor];
[self.view.layer addSublayer:shapeLayer];
这是我用来画线的代码片段,但使用这段代码我只能画实线,但我的客户需要许多自定义线,如虚线、虚线等和其他自定义线。我是Xcode新手,需要帮助才能做到这一点您可以使用以下方法更改线型
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:10],
[NSNumber numberWithInt:5],nil]];
shapelayer.lineJoin = kCALineJoinMiter;
shapelayer.lineDashPhase = 3.0f;
谢谢@rmrahul,这很有效。另外,如果我需要一条两边都像箭头的线,就像“这个”。你必须通过编程画“>”。检查一下这个想法