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扩展允许您使用多种方法在聚焦图形上下文(通常是NSView)中绘制属性字符串:drawAtPoint:,drawInRect:和(使用OS X v10.4及更高版本)drawWithRect:options:。 这些方法用于绘制少量必须很少绘制的文本或文本。 每次调用它们时,它们都会创建和处理各种支持文本对象。 要重复绘制字符串,使用NSLayoutManager会更有效,如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.
- 请注意,Application Kit也定义了NSString的绘制方法,允许任何字符串对象绘制自己。 这些方法,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:,有一种类似的方法来确定呈现NSString对象所需的矩形。
网友评论