scbas1000
scbas1000

Reputation: 121

How to change text of navigation bar (UISearchController)?

I have created a navigation bar with UISearchController.

Below is my code:

@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)
}

But I can't change the text.

enter image description here

Upvotes: 1

Views: 251

Answers (1)

Harshal Bhavsar
Harshal Bhavsar

Reputation: 1673

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

enter image description hereUse this to change your place holder text

Upvotes: 1

Related Questions