在IOS上更改虚线宽度

时间:2016-12-02 08:41:08

标签: ios objective-c swift

我使用this exampleuiview上绘制虚线:

 UIBezierPath *path = [UIBezierPath bezierPath];
 //draw a line
 [path moveToPoint:yourStartPoint]; //add yourStartPoint here
 [path addLineToPoint:yourEndPoint];// add yourEndPoint here
 [path stroke];

 float dashPattern[] = {1,1,1,1}; //make your pattern here
 [path setLineDash:dashPattern count:4 phase:0];

 UIColor *fill = [UIColor blueColor];
 shapelayer.strokeStart = 0.0;
 shapelayer.strokeColor = fill.CGColor;
 shapelayer.lineWidth = 7.0;
 shapelayer.lineJoin = kCALineJoinMiter;
 shapelayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:10], nil];
 shapelayer.lineDashPhase = 3.0f;
 shapelayer.path = path.CGPath;

它有效,但问题是即使我将uiview高度设置为1,我得到的线也很厚。 enter image description here

是否可以使它更薄?

1 个答案:

答案 0 :(得分:4)

您可以在代码的这一部分更改线条的粗细:

shapelayer.lineWidth = 7.0;

7.0更改为您想要的线条厚度。