是否可以在 UISearchBar 中设置光标。我知道 UITextField 可以实现,但我想知道 UISearchBar 是否可以实现。
对于文本字段,它是:
[textField setSelectedTextRange:...];
最佳答案
这不是最好的解决方案。但这仍然是解决方案。
这是 UISearchBar.h 的一部分:
NS_CLASS_AVAILABLE_IOS(2_0) @interface UISearchBar : UIView {
@private
UITextField *_searchField;
使用 KVC,您可以从搜索栏中获取文本字段:
UITextField *textField = [searchBar valueForKey: @"_searchField"];
然后处理文本字段:
[textField setSelectedTextRange:...];
关于ios - 如何设置UISearchBar的光标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18851526/