Hide UISearchBar clear text button

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

    Based on @Gines answer, here is the Swift version:

    func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
        guard let firstSubview = searchBar.subviews.first else { return }
    
        firstSubview.subviews.forEach {
            ($0 as? UITextField)?.clearButtonMode = .never
        }
    }
    

提交回复
热议问题