iPhone center text ShowTextAtPoint
iphone
Solution
Beter late than never:
First put the text on the view (in invisible mode):
CGTextDrawingMode mode = CGContextGetTextDrawingMode(ctx);
CGContextSetTextDrawingMode(ctx, kCGTextInvisible);
CGContextShowTextAtPoint(ctx, 0, 0, @"test", strlen("test"));
Then get the position of the text and set the mode back to visible:
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 put a new text on it.
CGContextShowTextAtPoint(ctx, 160 - pt.x / 2, 200, @"test", strlen("test"));
Problem
I am looking for a way to center text on the iPhone using the context.ShowTextAtPoint() method.