Hide UISearchBar clear text button

前端 未结 15 1593
时光说笑
时光说笑 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 05:59

    In Case of Swift 2.3 just use :

    var searchBar = UISearchBar();
    searchBar.frame = CGRectMake(0, 0, 00, 20))
    for subview: UIView in (searchBar.subviews.first?.subviews)!
            {
                if (subview.isKindOfClass(UITextField) )
                {
                    let textFieldObject = (subview as! UITextField)
                    textFieldObject.clearButtonMode = .Never;
                }
            }
    

提交回复
热议问题