我有一个名为SearchView的UIView,我将searchController.searchBar添加为UIView的子视图。
在viewDidLoad()中,我正在更改我的UISearchController中的搜索栏,如下所示:
//makes background transparent
searchController.searchBar.backgroundImage = UIImage()
//makes magnifying glass white
let iconView:UIImageView = tf!.leftView as! UIImageView
iconView.image = iconView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
iconView.tintColor = UIColor.whiteColor()
//changes text color to white
let tf = searchController.searchBar.valueForKey("searchField") as? UITextField
let attributedString = NSAttributedString(string: "", attributes:[NSForegroundColorAttributeName : UIColor.whiteColor()])
tf!.attributedPlaceholder = attributedString
tf!.textColor = UIColor.whiteColor()
//changes search field background color
tf!.backgroundColor = UIColor(red: 82/255, green: 91/255, blue: 93/255, alpha: 1)
//HERE: should make the cancel button font white...
searchController.searchBar.tintColor = UIColor.whiteColor()
searchView.addSubview(searchController.searchBar)
在AppDelegate中,我有
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()