在NSTextView中显示隐藏的字符 [英] Display hidden characters in NSTextView
问题描述
我正在为Mac OS X编写文本编辑器。我需要在NSTextView中显示隐藏的字符(例如空格,制表符和特殊字符)。我已经花了很多时间寻找如何做到这一点,但到目前为止,我还没有找到答案。如果有人能指出正确的方向,我将不胜感激。
I am writing a text editor for Mac OS X. I need to display hidden characters in an NSTextView (such as spaces, tabs, and special characters). I have spent a lot of time searching for how to do this but so far I have not found an answer. If anyone could point me in the right direction I would be grateful.
推荐答案
看看NSLayoutManager类。您的NSTextView将具有与其关联的布局管理器,并且布局管理器负责将字符(空格,制表符等)与字形(该字符在屏幕上绘制的图像)相关联。
Have a look at the NSLayoutManager class. Your NSTextView will have a layout manager associated with it, and the layout manager is responsible for associating a character (space, tab, etc.) with a glyph (the image of that character drawn on the screen).
在您的情况下,您可能对 replaceGlyphAtIndex:withGlyph:
方法,将允许您替换单个字形。
In your case, you would probably be most interested in the replaceGlyphAtIndex:withGlyph:
method, which would allow you to replace individual glyphs.
这篇关于在NSTextView中显示隐藏的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!