Limite la altura de UISearchBar en iOS 11
En iOS 11, la altura de la barra UISearch ha aumentado, pero quiero la misma altura que en iOS 10. ¿Cómo hacer eso? Estoy usando el siguiente código para crear el 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
}