Limitar a altura do UISearchBar no iOS 11
No iOS 11, a altura da barra do UISearch aumentou, mas eu quero a mesma altura do iOS 10. Como fazer isso? Estou usando o código abaixo para criar o searchController.
searchController = UIUtils.searchControllerInitialize(self)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.searchBar.delegate = self
viewTemp = UIView(frame: CGRect(x: 0.0, y: 64.0,width: UIScreen.main.bounds.size.width , height: 44))
viewTemp.addSubview(self.searchController.searchBar)
self.view.addSubview(viewTemp);
class func searchControllerInitialize(_ forViewController: UIViewController) -> UISearchController {
let controller = UISearchController(searchResultsController: nil)
controller.hidesNavigationBarDuringPresentation = true
// This property dismiss the background the navigation bar
controller.dimsBackgroundDuringPresentation = false
controller.definesPresentationContext = true
forViewController.definesPresentationContext = true
controller.searchBar.sizeToFit()
let topView: UIView = controller.searchBar.subviews[0] as UIView
for subView in topView.subviews {
if subView.isKind(of: NSClassFromString("UITextField")!) {
(subView as! UITextField).returnKeyType = UIReturnKeyType.search
(subView as! UITextField).enablesReturnKeyAutomatically = true
}
}
let viewS = UIView(frame: CGRect(x: 0.0, y: 0.0,width: UIScreen.main.bounds.size.width , height: 64))
viewS.backgroundColor = UIColor.DTColor()
controller.view.addSubview(viewS)
controller.hidesNavigationBarDuringPresentation = false
if #available(iOS 11.0, *) {
controller.searchBar.translatesAutoresizingMaskIntoConstraints = false
controller.searchBar.heightAnchor.constraint(equalToConstant: 44).isActive = true
}
return controller
}