Alexander Streltsov Alexander Streltsov - 1 month ago 28
Swift Question

Using CGContextSetTextDrawingMode with setLineWidth property (drawRect function)

How can I use "setLineWidth" and "setLineJoin" properties with CGContextSetTextDrawingMode in Swift?

override func drawRect(rect: CGRect) {

let context = UIGraphicsGetCurrentContext()
CGContextSetTextDrawingMode(context, CGTextDrawingMode.Stroke)

context?setLineWidth(2)
context.setLineJoin(CGLineJoin.Round)

}


Only properties (setLineWith and setLineJoin) are not working.
It worked one year ago. But now it does not work.

Answer

This works in Swift 3

let context = UIGraphicsGetCurrentContext()
    context!.setTextDrawingMode(CGTextDrawingMode.stroke)

    context?.setLineWidth(2.0)
    context?.setLineJoin(.round)