如何在 swift 5(iOS) 中创建虚线步骤指示器

阿努沙我的世界

我有一个要求,比如在 swift 5 中绘制一个虚线的步骤指示器。我已经搜索了很多相同的教程,但我无法得到正确的结果。我需要应该处于垂直位置(从上到下)的步长指示器。我使用了以下代码,但是当我在 iPad 中运行该应用程序时出现错误。

private func drawLinePath() {
       //let linePath = UIBezierPath()
         let  path = UIBezierPath()

         let centerX = self.frame.width / 2.0
         let lineHeight = self.frame.height / 10

          path.move(to: CGPoint(x: centerX, y: 0))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 3))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 5))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 8))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 10))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 12))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 15))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 18))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 21 ))

          path.move(to: CGPoint(x: centerX, y:lineHeight + 23))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 26))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 28))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 31))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 33))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 36))
          path.move(to: CGPoint(x: centerX, y:lineHeight + 38))
          path.addLine(to: CGPoint(x: centerX, y: lineHeight + 41))
          self.path = path.cgPath

        }

在此处输入图片说明

鲁奇·马卡迪亚

这是完美运行的代码。

 func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) {

    //design the path
    let path = UIBezierPath()
    path.move(to: start)
    path.addLine(to: end)

    //design path in layer
    let shapeLayer = CAShapeLayer()
    shapeLayer.path = path.cgPath
    shapeLayer.fillColor =  UIColor.clear.cgColor
    shapeLayer.strokeColor = lineColor.cgColor
    shapeLayer.lineWidth = 4.0
    shapeLayer.lineCap = .round
    shapeLayer.lineDashPattern =  [0.001,16]
    shapeLayer.lineDashPhase = 4
    view.layer.addSublayer(shapeLayer)
}

func drawLine() {
    let frm1: CGRect = img1.frame
    let frm2 : CGRect = img2.frame
    drawLineFromPoint(start: CGPoint(x: frm1.origin.x + 12, y: frm1.origin.y + 25), toPoint: CGPoint(x: frm1.origin.x + 12, y: frm2.origin.y), ofColor: UIColor.black, inView: self.view)
}


override func viewDidLoad() {
    super.viewDidLoad()
    drawLine()
}

这是图像

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在我的iOS应用中检查Google身份验证状态(Swift 5)

如何在带有Swift的iOS 8上显示带有文本的活动指示器?

如何在iOS Swift中为CMSampleBufferGetFormatDescription创建anAudioSampleBuffer

Swift中的加载指示器

Swift中的活动指示器

如何在iOS的CollectionView的页脚中添加加载指示器

如何在Swift中为iOS创建SDK?

如何在Nuxt.js中创建自定义加载指示器?

如何在bokeh中创建加载指示器?

如何在iOS Swift4中创建此圆形?

如何在NavigationDrawer中创建选项卡指示器?

如何在Apple Maps中更新路线-iOS 13.0中的Xcode Swift 5?

如何在Swift 5和iOS 13中使用CIFilter sunbeamsGenerator?

如何在Swift 5中遍历字典?

如何在iOS7的表格视图单元格中显示活动指示器

如何在单独的类中的iOS Swift中创建计时器?

如何在黑色透明方块中创建活动指示器加载警报?

Firebase图像上传进度屏幕指示器-Swift iOS

如何在Swift中根据“赢得,丢失,绘制”设置图形化的表单指示器

Swift:如何在最短的时间内显示活动指示器?

如何在 ios Swift 3 中从模型创建 JSON

如何获得 UICollectionView 的虚线页面指示器?

如何在 Swift 5 中创建一个变量?

如何在 Swift 5 中创建我自己的 UIAlertController?

如何在 iOS Swift 中创建此视图?

如何在 iOS swift 中订阅 UITextView?

如何在 Swift 的多个视图中使用一个活动指示器?

.addObservers 和 observevalue 方法如何在 iOS Swift 5 中工作

如何在 Flutter 中为 WebView 创建进度指示器