How to draw a triangle programmatically

前端 未结 3 1135
长情又很酷
长情又很酷 2020-12-13 04:43

I have a triangle solver, I want a way to use the values I get from the answer to draw a triangle to the screen that matches it.

3条回答
  •  甜味超标
    2020-12-13 04:44

    Swift 3 equivalent for progrmr's answer:

    override func draw(_ rect: CGRect) {
    
        guard let context = UIGraphicsGetCurrentContext() else { return }
    
        context.beginPath()
        context.move(to: CGPoint(x: rect.minX, y: rect.minY))
        context.addLine(to: CGPoint(x: rect.maxX, y: rect.midY))
        context.addLine(to: CGPoint(x: (rect.minX), y: rect.maxY))
        context.closePath()
    
        context.setFillColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        context.fillPath()
    }
    

提交回复
热议问题