Draw a line with UIBezierPath

前端 未结 4 1905
礼貌的吻别
礼貌的吻别 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:48

    Ended up doing it this way:

    func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) {
    
        //design the path
        var path = UIBezierPath()
        path.moveToPoint(start)
        path.addLineToPoint(end)
    
        //design path in layer
        var shapeLayer = CAShapeLayer()
        shapeLayer.path = path.CGPath
        shapeLayer.strokeColor = lineColor.CGColor
        shapeLayer.lineWidth = 1.0
    
        view.layer.addSublayer(shapeLayer)
    }
    

提交回复
热议问题