实现UISearchBar空字符串搜索 swift

xiaoxiao2021-02-28  107

自定义一个searchBar 在layoutSubview中设置搜索按钮长亮

class EliveSearchBar: UISearchBar {

    override init(frame: CGRect) {         super.init(frame: frame)              }     override func layoutSubviews() {         super.layoutSubviews()             if let searchTF: UITextField = self.value(forKey: "_searchField") as? UITextField{                 searchTF.enablesReturnKeyAutomatically = false             }         }     required init?(coder aDecoder: NSCoder) {         super.init(coder: aDecoder)         //fatalError("init(coder:) has not been implemented")     } }

注意:获取UISearchBar中textfield 

          let searchTF = searchBar.value(forKey: "_searchField") as? UITextField

         设置UISearchBar中的取消按钮中文显示

        searchBar.setValue("取消", forKey: "_cancelButtonText")

转载请注明原文地址: https://www.6miu.com/read-35744.html

最新回复(0)