objective-c: draw line on top of UIImage or UIImageView

前端 未结 3 763
自闭症患者
自闭症患者 2020-12-17 04:00

How do I draw a simple line on top of a UIImage or UIImageView?

3条回答
  •  清酒与你
    2020-12-17 04:35

    For Swift 3.0

        UIGraphicsBeginImageContext(originalImage.size)
        originalImage.draw(at: CGPoint(x: 0, y: 0))
        let context = UIGraphicsGetCurrentContext()!
        context.setLineWidth(2)
        context.move(to: CGPoint(x: 0, y: originalImage.size.height - 2))
        context.addLine(to: CGPoint(x: originalImage.size.width, y: originalImage.size.height - 2))
        context.setStrokeColor(UIColor.red.cgColor)
        context.strokePath()
        let finalImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    

提交回复
热议问题