Technical Q&A QA1051

How to measure CG text

Q:  How do I measure the width of my text before drawing it with Core Graphics?

A: First call CGContextGetTextPosition to find the current text position. Then, set the text drawing mode to kCGTextInvisible using CGContextSetTextDrawingMode and draw the text. Finally, call CGContextGetTextPosition again to determine the final text position. Take the difference between the starting and ending positions to find the width of your text.



Document Revision History


DateNotes
2007-08-02

minor cleanup and made 'Not Recomended'

2001-07-02

New document that explains how to measure Core Graphics text.