开发者

How to find the location of the cursor in a UITextView

开发者 https://www.devze.com 2023-02-19 12:46 出处:网络
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 yo

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

精彩评论

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