Untitled - MARKUP 1.12 KB
                    
             func drawLine(coords: Array<Int>) {
        UIGraphicsBeginImageContext(canvas.bounds.size)
        canvas.draw(canvas.bounds)
        let ctx=UIGraphicsGetCurrentContext()
        ctx?.move(to: CGPoint(x: coords[0], y: coords[1]))
        ctx?.addLine(to: CGPoint(x: coords[2], y: coords[3]))
        ctx?.setLineWidth(3)
        ctx?.setStrokeColor(UIColor.black.cgColor)
        ctx?.strokePath()
        canvas.image=UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
    func drawCircle(coords: Array<Int>) {
        UIGraphicsBeginImageContext(canvas.bounds.size)
        canvas.draw(canvas.bounds)
        let ctx=UIGraphicsGetCurrentContext()
        let rect = CGRect(x: coords[0], y: coords[1], width: coords[2], height: coords[3])
        ctx?.setStrokeColor(UIColor.black.cgColor)
        ctx?.setFillColor(UIColor.white.cgColor)
        ctx?.setLineWidth(3)
        ctx?.addEllipse(in: rect)
        ctx?.drawPath(using: .fillStroke)
        canvas.image=UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
            
            

Paste Hosted With By Wklejamy.pl