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 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.
- Application Kit的NSStringDrawing擴(kuò)展允許您使用多種方法在聚焦圖形上下文(通常是NSView)中繪制屬性字符串:drawAtPoint:,drawInRect:和(使用OS X v10.4及更高版本)drawWithRect:options:。 這些方法用于繪制少量必須很少繪制的文本或文本。 每次調(diào)用它們時(shí),它們都會(huì)創(chuàng)建和處理各種支持文本對(duì)象膊毁。 要重復(fù)繪制字符串,使用NSLayoutManager會(huì)更有效,如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 OS X v10.4 and later) drawWithRect:options:attributes:
, are described in NSString Additions.
- 請(qǐng)注意,Application Kit也定義了NSString的繪制方法父虑,允許任何字符串對(duì)象繪制自己该酗。 這些方法,drawAtPoint:withAttributes:士嚎,drawInRect:withAttributes:和(與OS X v10.4及更高版本)drawWithRect:options:attributes:呜魄,在NSString Additions中描述。
With 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:
.
- 使用OS X v10.4及更高版本莱衩,您可以使用boundingRectWithSize:options:找出布局屬性字符串所需的矩形爵嗅。 同樣,給定一組屬性boundingRectWithSize:options:attributes:笨蚁,有一種類似的方法來(lái)確定呈現(xiàn)NSString對(duì)象所需的矩形睹晒。