在光标位置插入一个文本字符串到NSTextView或使用Objective C选择文本 [英] Insert a string of text into an NSTextView at the cursor position or selection of text using Objective C
本文介绍了在光标位置插入一个文本字符串到NSTextView或使用Objective C选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用Objective C和可可使用Xcode?
我试图在单击按钮时在光标或用户选择处插入字符串。
How would I do this using Objective C and cocoa using Xcode? I am trying to insert a string at the cursor or user selection on the click of a button.
推荐答案
NSTextView有一个方法-insertText:它做你想要的:
NSTextView has a method -insertText: which does what you want:
[myTextView insertText:@"hello world"];
此方法接受NSString或NSAttributedString。
The method accepts either an NSString or an NSAttributedString.
这篇关于在光标位置插入一个文本字符串到NSTextView或使用Objective C选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文