简体   繁体   English

使用文本工具包和* not * UITextView绘制文本

[英]Drawing Text with Text Kit and *not* UITextView

I'm looking at TextKit and every tutorial I've come across gives me the same information: 我正在查看TextKit,我遇到的每个教程都为我提供了相同的信息:

NSTextStorage holds your string and font information, NSLayoutManager manages layout and glyphs, and NSTextContainer specifies areas that the text should be drawn to. NSTextStorage保存您的字符串和字体信息, NSLayoutManager管理布局和字形, NSTextContainer指定应将文本绘制到的区域。

Then, the next step is always UITextView. 然后,下一步始终是UITextView。 What if I want to draw the glyphs myself? 如果我想自己绘制字形怎么办? How might I go about doing that? 我该怎么做呢? How does UITextView do it? UITextView是如何做到的? Do I need to drop down to Core Text? 我需要下拉至“核心文字”吗?

It turns out that NSLayoutManager has some handy drawing methods that you can use. 事实证明, NSLayoutManager具有一些方便使用的绘制方法。 The documentation describes them. 文档描述了它们。 The simplest one is drawBackgroundForGlyphRange(_:atPoint:) which draws into a text container. 最简单的一个是drawBackgroundForGlyphRange(_:atPoint:) ,它可以绘制到文本容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM