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è)語(yǔ)音按鈕
// 右側(cè)語(yǔ)音 bar.showsBookmarkButton = true bar.setImage(#imageLiteral(resourceName: "VoiceSearchStartBtn"), for: .bookmark, state: .normal) 監(jiān)聽語(yǔ)音按鈕的點(diǎn)擊 // MARK:- UISearchBarDelegate extension LXFContactViewController: UISearchBarDelegate { func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) { LXFLog("點(diǎn)擊了語(yǔ)音按鈕") } }
右
右側(cè)語(yǔ)音效果
以上所述是小編給大家介紹的iOS中Swift UISearchController仿微信搜索框,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
iOS中使用UISearchBar控件限制輸入字?jǐn)?shù)的實(shí)現(xiàn)方法
這篇文章主要介紹了iOS中使用UISearchBar控件限制輸入字?jǐn)?shù)的實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下2016-08-08iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例
這篇文章主要介紹了iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-01-01ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲(chǔ)
這篇文章主要為大家介紹了ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲(chǔ)的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07IOS開發(fā)代碼分享之獲取啟動(dòng)畫面圖片的string
本文是IOS開發(fā)代碼分享系列的第一篇文章,這里分享下獲取啟動(dòng)畫面圖片的string的代碼,本代碼支持 iPhone 6 以下. 支持 iPhone 及 iPad,非常實(shí)用,希望對(duì)大家有所幫助2014-09-09iOS瀑布流的簡(jiǎn)單實(shí)現(xiàn)(Swift)
這篇文章主要介紹了iOS瀑布流的簡(jiǎn)單實(shí)現(xiàn),說(shuō)到瀑布流, 或許大家都不陌生, 瀑布流的實(shí)現(xiàn)也有很多種! 本文使用兩種方法介紹,有興趣的可以了解一下。2016-11-11IOS開發(fā)之JSON轉(zhuǎn)PLIST實(shí)例詳解
這篇文章主要介紹了IOS開發(fā)之JSON轉(zhuǎn)PLIST實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2016-11-11iOS實(shí)現(xiàn)翻頁(yè)效果動(dòng)畫實(shí)例代碼
本篇文章主要介紹了iOS實(shí)現(xiàn)翻頁(yè)效果動(dòng)畫實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05