简体   繁体   English

将文本字符串插入到光标位置的NSTextView中,或使用Objective C选择文本

[英]Insert a string of text into an NSTextView at the cursor position or selection of text using Objective C

How would I do this using Objective C and cocoa using Xcode? 我将如何使用Objective C和可可使用Xcode做到这一点? I am trying to insert a string at the cursor or user selection on the click of a button. 我试图在单击按钮的光标或用户选择的位置插入字符串。

NSTextView has a method -insertText: which does what you want: NSTextView具有-insertText:方法,该方法可以执行您想要的操作:

[myTextView insertText:@"hello world"];

The method accepts either an NSString or an NSAttributedString. 该方法接受NSString或NSAttributedString。

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

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