Better late than never:
First place the text in the view (in invisible mode):
CGTextDrawingMode mode = CGContextGetTextDrawingMode(ctx); CGContextSetTextDrawingMode(ctx, kCGTextInvisible); CGContextShowTextAtPoint(ctx, 0, 0, @"test", strlen("test"));
Then find the position of the text and return the mode to visibility mode:
CGPoint pt = CGContextGetTextPosition(ctx); CGContextSetTextDrawingMode(ctx, mode);
Now you have the position of the invisible text. Then use the center of the screen (160) and apply new text on it.
CGContextShowTextAtPoint(ctx, 160 - pt.x / 2, 200, @"test", strlen("test"));
source share