如何更改导航栏(UISearchController)的文本?

时间:2016-09-22 12:30:10

标签: swift xcode swift2 navigationbar uisearchcontroller

我创建了一个UISearchController的导航栏。

以下是我的代码:

@IBAction func showSearchController(sender: AnyObject) {
    let searchController = UISearchController(searchResultsController: searchResultController)
    searchController.searchBar.delegate = self
    /*
    searchController.searchBar.placeholder = "hhhhhhhhhhh"
    searchController.navigationItem.title = "hhhhhhhhhhh"
    searchController.navigationController?.navigationBar.topItem?.title = "hhhhhhhh"    -->i try these codes for to change*/

    self.presentViewController(searchController, animated: true, completion: nil)
}

但我无法改变文字。

enter image description here

1 个答案:

答案 0 :(得分:1)

var searchTextField = searchController.searchBar.valueForKey("_searchField") as! UITextField
searchTextField.placeholder = "Your Custom Text"

enter image description here使用此功能更改占位符文字