本文介绍了如何更改SearchBar边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将搜索栏
中的灰色边框颜色更改为白色。现在它看起来像这样:
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()
with
self.searchBar.searchBar.backgroundImage = UIImage(named:nameOfYourWhiteImage)
你将拥有一个干净的白色搜索栏。希望这能解决你的问题。祝你好运!
I would like to change grey border color in my Search Bar
to white color. Now it looks like that:
I achieved this effect after using this lines of code, but "inside border" is still grey:
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)
Can somebody help me in it?
解决方案
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()
Code above will give you all white searchbar but likely there will be black lines at top and bottom of the searchbar as you can see from the attachment. If you see the black lines and if you don't want them, change;
self.searchBar.searchBar.barTintColor = UIColor.whiteColor()
with
self.searchBar.searchBar.backgroundImage = UIImage(named: "nameOfYourWhiteImage")
And you will have a clean white searchbar. Hope this solves your problem. Good luck!
这篇关于如何更改SearchBar边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!