iOS - Swift UISearchController仿微信搜索框
2017-02-18 19:42
441 查看
0x01.创建一个UISearchController
如果传入的searchController为nil,则表示搜索的结果在当前控制器中显示,现在我让它在searchVC中显示.// 创建searchResultVC let searchVC = UIViewController() // 设置背景颜色为红色 searchVC.view.backgroundColor = UIColor.red let searchController = UISearchController(searchResultsController: searchVC) // 设置背景颜色 searchController.view.backgroundColor = UIColor (red: 0.97, green: 0.97, blue: 0.97, alpha: 1.0) // 默认为YES,设置开始搜索时背景显示与否 // searchController.dimsBackgroundDuringPresentation = false // 默认为YES,控制搜索时,是否隐藏导航栏 // searchController.hidesNavigationBarDuringPresentation = false // 将搜索框视图设置为tableView的tableHeaderView tableView.tableHeaderView = searchController.searchBar
0x02.设置搜索框
// 搜索框 let bar = searchController.searchBar // 样式 bar.barStyle = .default // 设置光标及取消按钮的颜色 bar.tintColor = RGBA(r: 0.12, g: 0.74, b: 0.13, a: 1.00) // 设置代理 bar.delegate = self
0x03.去除背景
// 去除背景及上下两条横线 bar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
0x04.添加右侧语音按钮
// 右侧语音 bar.showsBookmarkButton = true bar.setImage(#imageLiteral(resourceName: "VoiceSearchStartBtn"), for: .bookmark, state: .normal)
// MARK:- UISearchBarDelegate extension LXFContactViewController: UISearchBarDelegate { func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) { LXFLog("点击了语音按钮") } }
0x05.效果
相关文章推荐
- iOS - Swift UISearchController仿微信搜索框
- iOS中Swift UISearchController仿微信搜索框
- iOS - Swift UISearchController的取消按钮
- IOS UISearchController的简单开发实现(swift版)
- iOS - Swift UISearchController仿微信搜索框
- iOS UISearchController Class Reference
- iOS -- dismissViewControllerAnimated(Swift)
- Swift - iOS中各种视图控制器(View Controller)的介绍
- swift-教你如何实现导航上的UISearchController动画效果。
- [iOS Swift] 自定义转场动画 UIViewControllerAnimatedTransitioning 报错
- iOS开发——搜索框(UISearchController)
- [iOS学习]搜索框(UISearchController)最近踩过的坑
- iOS开发点滴 - 如何通过Segue写代码传递数据从一个ViewController到另一个ViewController(Swift代码)
- iOS Swift教程 Core Data (五)NSFetchedResultsController 上
- iOS开发 UISearchController的cancel按钮自定义中文取消,改变按钮标题颜色,去掉边框线
- Swift - UISearchController初步学习
- IOS Swift UITableViewcontroller实现点击空白处隐藏键盘
- ios swift UITabBarController
- iOS UISearchController
- iOS UISearchBar使用全解 搜索条使用大全 swift3