有什么方法可以让我通过文本字段的 UITextRange 对象获取 UITextField 当前的插入符位置吗? UITextField 返回的 UITextRange 有什么用吗? UITextPosition 的公共接口没有任何可见成员。
昨晚我遇到了同样的问题。事实证明,您必须在 UITextField 上使用 offsetFromPosition 来获取所选范围的“开始”的相对位置,以计算出位置。
e.g.
// 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/ http://neofight.wordpress.com/2012/04/01/finding-the-cursor-position-in-a-uitextfield/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)