Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用UIBezierPath绘制各种类型的线_Ios_Objective C_Uibezierpath - Fatal编程技术网

Ios 如何使用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];

我正在用UIBezierPath画一条线

[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,这很有效。另外,如果我需要一条两边都像箭头的线,就像“这个”。你必须通过编程画“>”。检查一下这个想法