iOS v10或更低版本:如何以编程方式在导航栏底部添加UISearchController



我的应用程序的iOS最低版本是10.3。我可以在iOS 11的导航栏底部添加搜索栏。但我想要更低版本的iOS 11也一样,它应该是程序化的。请帮忙。感谢

fileprivate func _setupNavigationBar() {
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Here"
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
} else {
// TODO: ????????????????
}
} 
class ViewController: UIViewController, UISearchControllerDelegate {
var controladorDeBusca: UISearchController!
var resultsTableViewController: ResultsTableViewController?
override func viewDidLoad() {
super.viewDidLoad()
resultsTableViewController = storyboard!.instantiateViewController(withIdentifier: "resultsTableViewController") as? ResultsTableViewController
setUpSearchAtNaviagtion()
}
func setUpSearchAtNaviagtion() {
controladorDeBusca = UISearchController(searchResultsController: resultsTableViewController)
controladorDeBusca.delegate = self
controladorDeBusca.searchResultsUpdater = resultsTableViewController
controladorDeBusca.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
controladorDeBusca.loadViewIfNeeded()
//Configura a barra do Controlador de busca
controladorDeBusca.searchBar.delegate = resultsTableViewController
controladorDeBusca.hidesNavigationBarDuringPresentation = false
controladorDeBusca.searchBar.placeholder = "Search place"
controladorDeBusca.searchBar.sizeToFit()
controladorDeBusca.searchBar.barTintColor = navigationController?.navigationBar.barTintColor
controladorDeBusca.searchBar.tintColor = self.view.tintColor
//Adiciona a barra do Controlador de Busca a barra do navegador
navigationItem.titleView = controladorDeBusca.searchBar
}
}

试试这个。。

相关内容

  • 没有找到相关文章

最新更新