将UISearchBar设置为正常工作时会遇到各种问题。它应该显示在navigationBar中。使用“旧”方式设置navigationItem.titleView = searchController.searchBar
。如下图所示,“取消”按钮的文本被截断了。任何想法如何解决这个问题?我试图将searchController.searchBar.sizeToFit()
设置为没有运气。
fileprivate lazy var searchController: UISearchController = {
let sc = UISearchController(searchResultsController: nil)
sc.delegate = self
sc.searchBar.delegate = self
sc.searchBar.returnKeyType = .done
sc.searchBar.tintColor = UIColor.black
sc.searchResultsUpdater = self
sc.hidesNavigationBarDuringPresentation = false
sc.dimsBackgroundDuringPresentation = false
return sc
} ()