NSTextView添加到所选文本的URL链接?

Le *_*kin 3 cocoa nstextview

我有一个NSTextView.

我只想NSLinkAttributeNameNSTextView...中的选定文本中添加一个属性(an )

你能帮助我吗 ?

谢谢.

Jen*_*fke 6

你想获得视图的textStorage(基本上是一个可变的属性字符串),然后将NSLinkAttributeName属性添加到选定的范围; 该属性的值是要链接的URL.

[[textView textStorage] addAttribute: NSLinkAttributeName value: url range:[textView selectedRange]];
Run Code Online (Sandbox Code Playgroud)