You can draw string objects directly in a focused NSView
using methods such as drawAtPoint:withAttributes: (to draw a string with multiple attributes, such as multiple text fonts, you must use an NSAttributedString
object). These methods are described briefly in Text in Cocoa Drawing Guide.
- 您可以使用诸如drawAtPoint:withAttributes之类的方法直接在聚焦的NSView中绘制字符串对象(要绘制具有多个属性的字符串,例如多个文本字体,您必须使用NSAttributedString对象)。 这些方法在“可可图绘制指南”中简要描述。
The simple methods, however, are designed for drawing small amounts of text or text that is only drawn rarely—they create and dispose of various supporting objects every time you call them. To draw strings repeatedly, it is more efficient to use NSLayoutManager
, as described in Drawing Stringsin Text Layout Programming Guide. For an overview of the Cocoa text system, of which NSLayoutManager
is a part, see Cocoa Text Architecture Guide.
- 然而,简单的方法是为了绘制少量只是很少绘制的文本或文本而设计的 - 每次调用它们时它们都会创建和处理各种支持对象。 要重复绘制字符串,使用NSLayoutManager会更有效,如“绘制字符串文本布局编程指南”中所述。 有关Cocoa文本系统的概述,其中NSLayoutManager是其中的一部分,请参阅Cocoa Text Architecture Guide。
网友评论