Add UITextField to title view of navigation item

前端 未结 2 1518
一向
一向 2021-02-20 09:27

How do you add a text field to the title view of a navigation item and have it sized correctly?

It works fine if I do this with a search bar like this but I don\'t know

2条回答
  •  [愿得一人]
    2021-02-20 09:56

    Class: ViewController: UISearchBarDelegate {
    
    let searchController = UISearchController(searchResultsController: nil)
    navigationItem.searchController = searchController
    navigationItem.searchController?.searchBar.delegate = self
    navigationItem.searchController?.obscuresBackgroundDuringPresentation = false
    navigationItem.searchController?.hidesNavigationBarDuringPresentation = false
    navigationItem.searchController?.searchBar.placeholder = "Enter text here..."
    

提交回复
热议问题