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
Using Swift 4:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
let attributes = [
NSAttributedStringKey.paragraphStyle: paragraphStyle,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12.0),
NSAttributedStringKey.foregroundColor: UIColor.blue
]
let myText = "HELLO"
let attributedString = NSAttributedString(string: myText, attributes: attributes)
let stringRect = CGRect(x: W/2 - 50, y: border, width: 100, height: H)
attributedString.draw(in: stringRect)
For Swift 4.2, change the above attributes
to:
let attributes: [NSAttributedString.Key : Any] = [
.paragraphStyle: paragraphStyle,
.font: UIFont.systemFont(ofSize: 12.0),
.foregroundColor: UIColor.blue
]