显示 UISearchBar“X”在文本字段内与相邻的取消按钮内

发布于 2024-08-03 21:01:23 字数 288 浏览 7 评论 0原文

我知道我可以将 UISearchBarshowsCancelButton 设置为 NO ...直到您点击搜索栏文本字段,然后出现取消按钮反正! (至少对我来说是这样。)

有没有办法在 UISearchBar 文本字段内的圆圈中显示“X”,而不是在其旁边显示单独的“取消”按钮?请注意,此按钮仅在搜索模式处于活动状态时显示,并且与 showsCancelButton 的设置无关。

I know I can set showsCancelButton to NO for a UISearchBar ... until you tap the search bar text field, and then the cancel button appears anyway! (At least it does for me.)

Is there a way to show the "X" in a circle within the UISearchBar text field vs. having that separate Cancel button show up adjacent to it? Note that this button only appears for me when search mode is active, and this is regardless of the setting for showsCancelButton.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

瑾夏年华 2024-08-10 21:01:23

请尝试此操作。

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    // only show the status bar's cancel button while in edit mode
    mySearchBar.showsCancelButton = NO;

}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    mySearchBar.showsCancelButton = NO;
}

使用此取消按钮时将不会显示,

try this

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    // only show the status bar's cancel button while in edit mode
    mySearchBar.showsCancelButton = NO;

}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    mySearchBar.showsCancelButton = NO;
}

when using this cancel button will not shown.

高速公鹿 2024-08-10 21:01:23
for (UIView *searchBarSubview in [searchBar subviews]) {

    if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {

         [(UITextField *)searchBarSubview setClearsOnBeginEditing:YES];
    }
}

要启用cancelButton,请尝试searchBar.showsCancelButton = YES;
尝试上面的代码行。

for (UIView *searchBarSubview in [searchBar subviews]) {

    if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {

         [(UITextField *)searchBarSubview setClearsOnBeginEditing:YES];
    }
}

to enable the cancelButton try searchBar.showsCancelButton = YES;
Try the above lines of code.

抠脚大汉 2024-08-10 21:01:23

如果您使用界面生成器,则很容易显示。默认情况下它就在那里。我在我的应用程序中使用了搜索栏,并且搜索栏文本字段有一个“X”来清除文本字段

if you use interface builder it is ery easy to show.it is there by default.i have used search bar in my app and the searchbartextfield has an "X" to clear the textfield

甜嗑 2024-08-10 21:01:23

“X”可能只是为了清除搜索字段而不是取消搜索,因此一旦搜索正在进行,无论showsCancelButton如何,取消按钮都必须保留。

It might be that the "X" is only intended to clear the search field and not to cancel the search, and so the Cancel button must remain once a search is in play, regardless of showsCancelButton.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文