Draw a line with UIBezierPath

前端 未结 4 1911
礼貌的吻别
礼貌的吻别 2020-12-08 04:22

First time using BezierPaths, wondering how this function is actually supposed to be implemented. Currently the bezier path moves within the frame of the image, as opposed t

4条回答
  •  半阙折子戏
    2020-12-08 04:51

    Swift 4

    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.strokeColor = lineColor.cgColor
        shapeLayer.lineWidth = 1.0
    
        view.layer.addSublayer(shapeLayer)
    }
    

提交回复
热议问题