rgoncalv rgoncalv - 1 year ago 147
Swift Question

CGContextSetTextPosition does not work on Swift 3.0

I was using the following call:

CGContextSetTextPosition(context, 0, -bounds.origin.y)

After I upgraded to Xcode 8 and Swift 3, I am getting the following error:

'CGContextSetTextPosition' is unavailable: Use var textPosition

After going through Apple documentation, I realized the textPosition property is actually a getter that only "Returns the location at which text is drawn." It does not set anything and doesn't seem to have a setter function for text position in the documentation.

What should I do to set the text position then?

Obj-c code is welcome as well.

Answer Source

You need to use textPosition on CGContext like this.

context.textPosition = CGPoint(x:0, y:-bounds.origin.y)

For more deatil read Apple Documentation of Core Graphics for textPosition.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download