gpt4 book ai didi

ios - 如何设置光标位置 UISearchBar?

转载 作者:行者123 更新时间:2023-11-29 10:54:52 37 4
gpt4 key购买 nike

是否可以在 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/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com