Hide UISearchBar clear text button

前端 未结 15 1608
时光说笑
时光说笑 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:10

    Swift 5

    Just add a single line below

    searchBar.searchTextField.clearButtonMode = .never
    
    0 讨论(0)
  • 2020-12-31 06:15

    You can remove the clear text button for all UISearchBar instances:

    [UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].clearButtonMode = UITextFieldViewModeNever;
    
    0 讨论(0)
  • 2020-12-31 06:15

    Converting Soto_iGhost's answer to Swift 4:

    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
    
        let textField: UITextField = searchBar.value(forKey: "_searchField") as! UITextField
        textField.clearButtonMode = .never
    }
    

    If you have an outlet of UISearchBar the you can write above code anywhere in your class.

    0 讨论(0)
提交回复
热议问题