如何在uitextview中的任何光标位置插入文本? [英] how to insert text at any cursor position in uitextview?
问题描述
我想实现Code,通过它我可以开始在iphone sdk中的UITextView中的光标的任何位置插入文本
i want to implement Code by which i can start to insert text at any position of cursor in UITextView in iphone sdk
任何想法?
提前谢谢..
any idea? thank you in advance..
我在这条链接中提到了: iPhone SDK:如何创建一个UITextView,在你点击的位置插入文字?
i refereed this link: iPhone SDK: How to create a UITextView that inserts text where you tap?
但没有得到它。
推荐答案
Dan的答案是手动更改文本。它与UITextView的UndoManager不兼容。
Dan's answer is manually changing the text. It's not playing well with UITextView's UndoManager.
实际上,使用UITextInput协议API插入文本非常容易,UITextView和UITextField支持它。
Actually it's very easy to insert text with UITextInput protocol API, which is supported by UITextView and UITextField.
[textView replaceRange:textView.selectedTextRange withText:insertingString];
注意:它是UITextInput协议中的 selectedTextRange ,而不是 selectedRange
Note: It's selectedTextRange in UITextInput protocol, rather than selectedRange
这篇关于如何在uitextview中的任何光标位置插入文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!