【发布时间】:2011-03-25 11:22:04
【问题描述】:
当我第一次单击包含一些文本的 UITextView 时,我想获取光标的当前位置。
【问题讨论】:
标签: iphone uitextview
当我第一次单击包含一些文本的 UITextView 时,我想获取光标的当前位置。
【问题讨论】:
标签: iphone uitextview
我相信 UITextView selectedRange 属性应该提供您所追求的。
【讨论】:
您可以使用 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?
也可以在 Apple 论坛上阅读相同内容。
【讨论】: