ios - 在 IOS 上更改虚线粗细

标签 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

可以再薄一点吗?

最佳答案

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

shapelayer.lineWidth = 7.0;

7.0 更改为您希望线条具有的任何粗细。

关于ios - 在 IOS 上更改虚线粗细,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40927930/

相关文章:

iphone - iOS:如何在应用程序崩溃时捕获所有错误数据?

ios - UILocalNotification 在字典中标记为不明确

iphone - NSNotificationCenter 一个帖子导致观察者被调用两次

ios - Objective-C:如何让AVPlayer在后台继续播放

ios - AVAudioEngine.start() 中的崩溃,即使它被包裹在 do/catch 中

ios - Swift:不需要全局 Var 声明

ios - swift iOS 10 无法重新注册推送通知,缺少什么?

html - Bootstrap Modal 按钮不起作用,仅适用于 iOS

ios - 从 Titanium 应用程序更新密码字段

ios - 设置 statusBar 样式不起作用 Objective-C