3
votes

When I update the placeholder text in the UISearchController's search bar to something wider than the search bar, this happens to the search icon:

enter image description here

I added the UISearchController and search bar by calling the following method in viewDidLoad:

private func initSearchController() {

    searchResultsController = UITableViewController()
    searchResultsController.tableView.backgroundColor = UIColor(red: 51/255, green: 51/255, blue: 51/255, alpha: 1.0)
    searchController = UISearchController(searchResultsController: searchResultsController)
    searchResultsController.tableView.rowHeight = 50

    let textFieldInsideSearchBar = searchController.searchBar.valueForKey("searchField") as? UITextField
    textFieldInsideSearchBar?.textColor = UIColor.whiteColor()
    searchController.searchBar.sizeToFit()
    searchController.searchBar.placeholder = "SOL Southwest Kitchen & Tequila Bar"

    searchController.hidesNavigationBarDuringPresentation = false
    searchController.dimsBackgroundDuringPresentation = true
    searchController.searchBar.searchBarStyle = .Minimal
    navigationItem.titleView = searchController.searchBar
    definesPresentationContext = true

    searchController.searchResultsUpdater = self
    searchResultsController.tableView.dataSource = self
    searchResultsController.tableView.delegate = self
    searchController.searchBar.delegate = self

}

What gives? Also, anyway to remove that weird gap between the back button and the search bar? If it helps, this view is the second view controller in a Navigation Controller. Using iOS9 and Swift 2.1. Thanks!

1
Moving the magnifying glass over to make room for placeholder text is, unfortunately, the standard behavior for uisearchbar, even if that means the magnifying glass is clipped. Tapping on the search bar will cause the magnifying glass to become visible again. The easiest way to avoid this is to use a shorter placeholder string. Your string is being truncated as is anyway. The placeholder text is meant to be descriptive (e.g. search, search locations, search contacts, search food & drinks, etc.)beyowulf
It will look much nicer, and be in line with Apple's guidelines, if you move the search bar under the navigation bar, e.g. look at Mail app how they have put the search bar.henrikstroem
Yeah I decided to change it back to a default placeholder text that fit.Patrick Kelly

1 Answers

2
votes

It seems as though this is not possible unless a custom search bar is created with a button, image, and text field.