Hide UISearchBar clear text button

前端 未结 15 1757
时光说笑
时光说笑 2020-12-31 05:31

I would like to know how to hide or not display the UISearchBar cross that appears in the textField fo the UISearchBar

I have

15条回答
  •  旧巷少年郎
    2020-12-31 06:05

    I tried different solutions about this issue, even the one selected in this post, but they didn't work.

    This is the way I found to solve this issue:

    UIView *subview = [[searchBar subviews] firstObject]; //SearchBar only have one subview (UIView)
    
    //There are three sub subviews (UISearchBarBackground, UINavigationButton, UISearchBarTextField)
    for (UIView *subsubview in subview.subviews)
    {
        //The UISearchBarTextField class is a UITextField. We can't use UISearchBarTextField directly here.
        if ([subsubview isKindOfClass: [UITextField class]])
        {
                [(UITextField *)subsubview setClearButtonMode:UITextFieldViewModeNever];
        }
    }
    

提交回复
热议问题