我想改变我Search Bar
的白色灰色边框颜色.现在它看起来像这样:
使用这行代码后我实现了这个效果,但"内部边框"仍然是灰色的:
var searchBar: UISearchController! self.searchBar.searchBar.backgroundColor = UIColor.whiteColor() self.searchBar.searchBar.layer.borderWidth = 3 self.searchBar.searchBar.layer.borderColor = UIColor.whiteColor().CGColor self.searchBar.searchBar.layer.backgroundColor = UIColor.whiteColor().CGColor self.searchBar.searchBar.tintColor = UIColor(red: 0.3, green: 0.63, blue: 0.22, alpha: 1)
有人可以帮助我吗?
self.searchBar.searchBar.searchBarStyle = UISearchBarStyle.Prominent self.searchBar.searchBar.translucent = false let textFieldInsideSearchBar = self.searchBar.searchBar.valueForKey("searchField") as? UITextField textFieldInsideSearchBar?.backgroundColor = UIColor.whiteColor() self.searchBar.searchBar.barTintColor = UIColor.whiteColor()
上面的代码将为您提供所有白色搜索栏,但可能会在搜索栏的顶部和底部显示黑线,您可以从附件中看到.如果你看到黑线,如果你不想要它们,改变;
self.searchBar.searchBar.barTintColor = UIColor.whiteColor()
同
self.searchBar.searchBar.backgroundImage = UIImage(named: "nameOfYourWhiteImage")
你会有一个干净的白色搜索栏.希望这能解决你的问题.祝好运!