2011-03-25 65 views
1

光标的位置,想获得光标的当前位置,当我第一次点击包含一些文本一个UITextView。我如何找到一个UITextView

+1

的可能重复的[获取在iPhone上的一个UITextView光标位置?(http://stackoverflow.com/questions/618759/getting-cursor-position-in-a-uitextview-on-在-iphone) – 2011-03-25 11:32:46

回答

1

我相信UITextViewselectedRange属性应该提供什么你之后。

1

你可以使用的UITextView的到的selectedRange返回插入点PF文本。 下面的代码演示了如何给它。

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]; 

为更多阅读SO邮政

Getting cursor position in a UITextView on the iPhone?

又看了苹果论坛相同。

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

相关问题