Skip to content

Drawing Strings

binism edited this page May 2, 2016 · 3 revisions

Drawing Strings

绘制字符串

你可以在NSView中使用drawAtPoint:withAttributes:方法直接绘制字符串(来绘制多个属性的字符串,如多个文本字体,你必须使用一个NSAttributedString对象)。这些方法在文本Cocoa Drawing Guide有简要的介绍。

但是,简单的方法是为那些少量文本的绘制或那些很少会被绘制的文本而设计的。它们会在每一次调用时创建并处理各种所支持的对象。为了重复地绘制字符串,使用NSLayoutManager将会是高效的方法,就像Text Layout Programming Guide中绘制字符串中描述的那样。NSLayoutManager 是Cocoa文本系统的一部分,有关Cocoa文本系统,参见Cocoa Text Architecture Guide。

Clone this wiki locally