UISearchController显示问题-iPhone X和其他设备

时间:2018-07-13 08:02:49

标签: ios swift uinavigationbar uisearchbar uisearchcontroller

我已经实现了UISearchController并将其显示在UIViewController上。

导航栏具有search按钮,并且在单击搜索时,将从屏幕顶部显示UISearchController

问题是,在iPhone X中,它看起来不错,但在所有其他设备中,间距不合适。

enter image description here

我的实现是这样的:

let searchController = UISearchController(searchResultsController: nil)

searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
searchController.searchBar.tintColor = UIColor.white
searchController.searchBar.sizeToFit()
searchController.searchBar.placeholder = SEARCH
searchController.searchBar.barTintColor = UIColor(hex: 0x2A3442)
searchController.searchBar.becomeFirstResponder()

// Search bar UI change
for subview in searchController.searchBar.subviews {
    for innerSubview in subview.subviews {
        if innerSubview is UITextField {
            let textField = innerSubview as? UITextField
            textField?.textColor = UIColor.white
            textField?.borderStyle = .roundedRect
            textField?.backgroundColor = UIColor(hex: 0x38465A)
        }
    }
}

present(searchController, animated: true)

0 个答案:

没有答案