Background: I am drawing on a UIImageView with Core Graphics. I would like to ultimately draw a text string over the core graphics drawing.
This (hackingwithswift.com) m
Swift 3.0 : to draw text
func drawMyText(myText:String,textColor:UIColor, FontName:String, FontSize:CGFloat, inRect:CGRect){
let textFont = UIFont(name: FontName, size: FontSize)!
let textFontAttributes = [
NSFontAttributeName: textFont,
NSForegroundColorAttributeName: textColor,
] as [String : Any]
myText.draw(in: inRect, withAttributes: textFontAttributes)
}
call this function , below is e.g.
let _rect = CGRect(x: 40, y: 100, width: 40, height: 40)
drawMyText(myText: "Hello", textColor: UIColor.black, FontName: "Helvetica Bold", FontSize: 11 , inRect:_rect)