jazzedge
11/28/2017 - 8:53 PM

Swift - Function to draw a line

Source: BorgGreen

    func drawLine(xorig: CGFloat, yorig: Int, xlen: Int, ylen: Int, color: CGColor) {

        let doYourPath = UIBezierPath(rect: CGRect(x: Int(xorig), y: yorig, width: xlen, height: ylen))
        let layer = CAShapeLayer()
        layer.path = doYourPath.cgPath
        layer.strokeColor = color
        layer.fillColor = color

        self.view.layer.addSublayer(layer)
    }