Draws the receiver with the specified options and other display characteristics of the given attributes, within the specified rectangle in the current graphics context.
SDK
- macOS 10.4–10.11Deprecated
Framework
- App
Kit
Declaration
func draw(with rect: NSRect, options: NSString.Drawing Options = [], attributes: [NSAttributed String.Key : Any]? = nil)
Parameters
rect
The rectangle in which to draw the string.
options
String drawing options.
attributes
A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an
NSAttributed
object, but in the case ofString NSString
objects, the attributes apply to the entire string, rather than ranges within the string.
Discussion
This method works in single-line, baseline rendering configuration by default. That is, the rect
argument's origin
field specifies the rendering origin, and that point is interpreted as the baseline origin by default. If the string drawing option NSString
is specified, origin
is interpreted as the upper left corner of the line fragment rectangle, and the method behaves in multiline configuration.
The size
field specifies the text container size. The width
part of the size field specifies the maximum line fragment width if larger than 0
. The height
defines the maximum size that can be occupied with text if larger than 0
and NSString
is specified. If NSString
is not specified, height is ignored and considered to be single-line rendering (NSLine
and NSLine
are treated as NSLine
).
You should only invoke this method when there is a current graphics context.