UISearchController iOS 11 Customization

后端 未结 9 1343
南旧
南旧 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: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.

提交回复
热议问题