开发者

How to find the location of the cursor in a UITextView

I want to get the current pos开发者_StackOverflow中文版ition of cursor when I first click on a UITextView that contains some text.


I believe the UITextView selectedRange property should provide what you're after.


you could use UITextView's selectedRange to return the insertion point pf text. The below code shows how to it.

NSString *contentsToAdd = @"some string";
NSRange cursorPosition = [tf selectedRange];
NSMutableString *tfContent = [[NSMutableString alloc] initWithString:[tf text]];
[tfContent insertString:contentsToAdd atIndex:cursorPosition.location];
[theTextField setText:tfContent];
[tfContent release];

for More to read the SO Post

Getting cursor position in a UITextView on the iPhone?

Also read the same on Apple discussion forum.

http://discussions.apple.com/thread.jspa?messageID=9940169

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜