UISearchController iOS 11 Customization

后端 未结 9 1179
南旧
南旧 2021-01-29 21:40

I had been using the following code prior to iOS 11 to customize the appearance of the UISearchController search bar:

var searchController = UISearc         


        
相关标签:
9条回答
  • 2021-01-29 22:33

    Try setting the search bar's bar style.

    searchController.searchBar.barStyle = UIBarStyleBlack;
    

    0 讨论(0)
  • 2021-01-29 22:42

    To properly set the text typed into the search bar to white use (when using a dark field color):

    searchController.searchBar.barStyle = .black
    

    To set the textfield background color

    if #available(iOS 11.0, *) {
    
            if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {
                if let backgroundview = textfield.subviews.first {
    
                    // Background color
                    backgroundview.backgroundColor = UIColor.white
    
                    // Rounded corner
                    backgroundview.layer.cornerRadius = 10;
                    backgroundview.clipsToBounds = true;
                }
            }
        }
    

    However using something like

    textfield.textColor = UIColor.blue
    

    in the above does not seem to work.

    0 讨论(0)
  • 2021-01-29 22:44

    If you need to change the background colour of the textField in the searchBar, see my answer here: https://stackoverflow.com/a/46315974/1109892

    0 讨论(0)
提交回复
热议问题