iOS中Swift UISearchController仿微信搜索框
創(chuàng)建一個(gè)UISearchController
如果傳入的searchResultsController為nil,則表示搜索的結(jié)果在當(dāng)前控制器中顯示,現(xiàn)在我讓它在searchResultVC中顯示
// 創(chuàng)建searchResultVC let searchResultVC = UIViewController() // 設(shè)置背景顏色為紅色 searchResultVC.view.backgroundColor = UIColor.red let searchController = UISearchController(searchResultsController: searchResultVC) // 設(shè)置背景顏色 searchController.view.backgroundColor = UIColor (red: 0.97, green: 0.97, blue: 0.97, alpha: 1.0) // 默認(rèn)為YES,設(shè)置開始搜索時(shí)背景顯示與否 // searchController.dimsBackgroundDuringPresentation = false // 默認(rèn)為YES,控制搜索時(shí),是否隱藏導(dǎo)航欄 // searchController.hidesNavigationBarDuringPresentation = false // 將搜索框視圖設(shè)置為tableView的tableHeaderView tableView.tableHeaderView = searchController.searchBar

添加searchBar
設(shè)置搜索框
// 搜索框 let bar = searchController.searchBar // 樣式 bar.barStyle = .default // 設(shè)置光標(biāo)及取消按鈕的顏色 bar.tintColor = RGBA(r: 0.12, g: 0.74, b: 0.13, a: 1.00) // 設(shè)置代理 bar.delegate = self

設(shè)置光標(biāo)及取消按鈕的顏色
去除背景
// 去除背景及上下兩條橫線 bar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)

去除背景及上下兩條橫線
添加右側(cè)語音按鈕
// 右側(cè)語音
bar.showsBookmarkButton = true
bar.setImage(#imageLiteral(resourceName: "VoiceSearchStartBtn"), for: .bookmark, state: .normal)
監(jiān)聽語音按鈕的點(diǎn)擊
// MARK:- UISearchBarDelegate
extension LXFContactViewController: UISearchBarDelegate {
func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {
LXFLog("點(diǎn)擊了語音按鈕")
}
}
右
右側(cè)語音效果
以上所述是小編給大家介紹的iOS中Swift UISearchController仿微信搜索框,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
iOS中在APP內(nèi)加入AppStore評(píng)分功能的實(shí)現(xiàn)方法
這篇文章主要介紹了iOS中在APP內(nèi)加入AppStore評(píng)分功能的實(shí)現(xiàn)方法,文中筆者給大家整理了三種方式,大家可以根據(jù)自己的需求選擇,需要的朋友可以參考下2017-11-11
iOS中創(chuàng)建表格類視圖WBDataGridView的實(shí)例代碼
這篇文章主要介紹了iOS中創(chuàng)建表格類視圖WBDataGridView的實(shí)例代碼,需要的朋友可以參考下2017-02-02

