简体   繁体   English

如何在NSTextView中的NSString周围添加框

[英]How to add box around NSString inside NSTextView

I'm working on a OS X application and I'm pretty much stuck at this. 我正在OS X应用程序上工作 ,我对此深陷其中。 I have some text inside NSTextView and I would like to put box around some strings (I have ranges for those substrings). 我在NSTextView有一些文本,我想将框放在一些字符串周围(我有这些子字符串的范围)。

Any ideas? 有任何想法吗?

Also, perfect solution would be to create something similar that Xcode has, when you type for example [NSString stringWithFormat: (NSString *), ..)]; 同样,完美的解决方案是在键入例如[NSString stringWithFormat: (NSString *), ..)];时创建与Xcode类似的东西[NSString stringWithFormat: (NSString *), ..)]; Screenshot: 屏幕截图: 自动完成建议

I'm interested in that blue box which suggests what type is expected. 我对这个蓝框感兴趣,该蓝框表明了预期的类型。 Any help would be really appreciated! 任何帮助将非常感激!

This question is not entirely related to possible duplicate question, since they are working on iOS application with slightly different approach. 这个问题与可能的重复问题并不完全相关,因为它们在iOS应用程序上的工作方式略有不同。

I'm pretty sure that Xcode achieves these effects using NSTextAttachment objects embedded within NSAttributedString instances. 我很确定Xcode使用嵌入在NSAttributedString实例中的NSTextAttachment对象可以达到这些效果。 (The same sort of effect can be seen in their NSTokenField control, which definitely uses this approach). (可以在其NSTokenField控件中看到相同的效果,该控件肯定使用此方法)。

在此处输入图片说明

It's a pretty big topic though: you need to be proficient with attributed strings, text attachments, the NSTextAttachmentCell class and a few other bits and pieces from Cocoa's text architecture. 但是,这是一个很大的话题:您需要精通属性字符串,文本附件, NSTextAttachmentCell类以及Cocoa文本体系结构中的其他点点滴滴。 The job is made all the more difficult by the fact that there's very little documentation (official or unoffical) for doing this sort of thing. 由于很少有文档(正式的或非正式的)来做这种事情,因此工作变得更加困难。

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

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