< Previous PageNext Page > Hide TOC

Drawing Attributed Strings

The Application Kit’s NSStringDrawing extensions let you draw an attributed string in a focused graphics context (typically an NSView) using a number of methods: drawAtPoint:, drawInRect:, and (with Mac OS X v10.4 and later) drawWithRect:options:. These methods are designed for drawing small amounts of text or text that must be drawn rarely. They create and dispose of various supporting text objects every time you call them. To draw strings repeatedly, it is more efficient to use NSLayoutManager, as described in “Drawing Strings”.

Note that the Application Kit defines drawing methods for NSString as well, allowing any string object to draw itself. These methods, drawAtPoint:withAttributes:, drawInRect:withAttributes:, and (with Mac OS X v10.4 and later) drawWithRect:options:attributes:, are described in NSString Additions.

With Mac OS X v10.4 and later, you can find out the rectangle required to lay out an attributed string using the method, boundingRectWithSize:options:. Again, there is an analogous method to determine the rectangle required to render an NSString object, given a set of attributes—boundingRectWithSize:options:attributes:.



< Previous PageNext Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-06-04)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.