UISearchBar中有一控件(UITextField),如果大家看图层关系的话,很容易看到这个控件,我们要改变的大部分也是这个控件的属性
获取UISearchBar中的UITextField:
var searchBar = UISearchBar()
let searchField = searchBar.value(forKey:"searchField")as!UITextField//输入框
let placeholderLabel = searchField.value(forKey:"placeholderLabel")as!UILabel//输入框中占位Label获取,之后可以更改字体颜色、大小等;
searchBar.setImage(UIImage(named: "searchBar_icon"), for: UISearchBarIcon.search, state: UIControlState.normal)//替换收缩放大镜
若想要不显示UISearchBar中右边的灰色叉形灰色按钮,方法是:searchField.clearButtonMode= .never
网友评论