我使用this example在uiview
上绘制虚线:
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,我得到的线也很厚。
是否可以使它更薄?
答案 0 :(得分:4)
您可以在代码的这一部分更改线条的粗细:
shapelayer.lineWidth = 7.0;
将7.0
更改为您想要的线条厚度。