【问题标题】:How to find the location of the cursor in a UITextView如何在 UITextView 中找到光标的位置
【发布时间】:2011-03-25 11:22:04
【问题描述】:

当我第一次单击包含一些文本的 UITextView 时,我想获取光标的当前位置。

【问题讨论】:

标签: iphone uitextview


【解决方案1】:

我相信 UITextView selectedRange 属性应该提供您所追求的。

【讨论】:

    【解决方案2】:

    您可以使用 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 论坛上阅读相同内容。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多