开发者

How to figure out the current caret position in a UITextField?

I want to programmatically paste a string into a text field or text view at the c开发者_如何学Gourrent caret position.

Is there an easy way to do this? I would need to know the current caret position, but there's no method to retrieve it, right? Don't want to call private API. Is there any legal way to do it?


Use UITextView's selectedRange method. If the range has a non-zero length (in the case of the user having selected some text), just take the location (or NSMaxRange(), or replace the entire range...)


Instead of pasting option. Get the string from textfield or textview insert the string which you want to paste it by providing the index and then clear the textfield then pass the string which you inserted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜