【发布时间】:2013-10-22 13:29:02
【问题描述】:
我有一个 UISearchBar,我试图在其上设置光标位置。我正在使用 UITectField 代表,因为我找不到任何直接用于 UISearchBar 的内容。以下是我正在使用的代码:
UITextField *textField = [searchBar valueForKey: @"_searchField"];
// Get current selected range , this example assumes is an insertion point or empty selection
UITextRange *selectedRange = [textField selectedTextRange];
// Construct a new range using the object that adopts the UITextInput, our textfield
UITextRange *newRange = [textField textRangeFromPosition:selectedRange.start toPosition:selectedRange.end];
问题在 'toPosition' 的 'newRange' 对象中我想要类似 selectedRange.end-1;因为我希望光标位于倒数第二个位置。
如何将光标设置到倒数第二个位置?
【问题讨论】:
标签: ios objective-c uitextfield int uitextposition