- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
有什么方法可以让我通过文本字段的 UITextRange 对象获得 UITextField 的当前插入符号位置? UITextField 返回的 UITextRange 是否有任何用处? UITextPosition 的公共(public)接口(interface)没有任何可见成员。
最佳答案
我昨晚遇到了同样的问题。事实证明,您必须在 UITextField 上使用 offsetFromPosition 来获取所选范围“开始”的相对位置才能计算出位置。
例如
// Get the selected text range
UITextRange *selectedRange = [self selectedTextRange];
//Calculate the existing position, relative to the beginning of the field
int pos = [self offsetFromPosition:self.beginningOfDocument
toPosition:selectedRange.start];
我最终使用了 endOfDocument,因为在更改文本字段后更容易恢复用户的位置。我在这里写了一篇博客:
http://neofight.wordpress.com/2012/04/01/finding-the-cursor-position-in-a-uitextfield/
关于ios - UITextField 中的 UITextPosition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766077/
我有一个 UISearchBar,我试图在其上设置光标位置。我正在使用 UITectField 委托(delegate),因为我找不到任何直接用于 UISearchBar 的东西。下面是我正在使用的代
我需要使用 NSStringFromRange 但我只有一个开始和结束 UITextPositions。如何将 UITextPosition 转换为 NSRange。 NSMutableArray *
有什么方法可以让我通过文本字段的 UITextRange 对象获得 UITextField 的当前插入符号位置? UITextField 返回的 UITextRange 是否有任何用处? UIText
我一直在上下搜索,但不知道该怎么做。假设我有一个这样的字符串: NSString *string = @"&foo !foo"; 我想要做的是区分 TextView 中的两个 foo(听起来很有趣哈哈
我需要获取 UIText 范围开始和结束的数值。到目前为止,我只能将描述打印为字符串。 通过查看 selectedTextRange,我认为它可能是一个结构?如何获取结构的元素? UITextRang
我正在尝试使用其 selectedTextRange 属性(从 UITextInput protocol 获得)来确定 UITextField 实例的文本选择的开始和结束位置.但是,我不知道如何访问构
我试图使用 UITextView characterRangeAtPoint在我的代码中获取 UITextRanges在某些 CGPoints在 TextView 中。然后我使用了UITextPosi
我是一名优秀的程序员,十分优秀!