How to change background color of UiSearchBar to black -SWIFT

南笙酒味 提交于 2020-01-13 03:38:48

问题


I created UISearchBar programmatically as below and the button appears to be of second image.How to clear the white color of search bar and set background colour to Black

var categorySearchBar : UISearchBar = UISearchBar()
        categorySearchBar.frame = CGRectMake(0, 20, self.view.frame.size.width, 30)
        categorySearchBar.layer.borderColor = UIColor.grayColor().CGColor
        categorySearchBar.layer.borderWidth = 1.0
        categorySearchBar.placeholder = "SEARCH"
        categorySearchBar.barTintColor = UIColor.blackColor()
        self.view.addSubview(categorySearchBar)


回答1:


You can use barStyle property of UISearchBar , if you are using story board you can use Attribute Inspector to change bar style, or use following code segment. It might help mate :)

categorySearchBar.barStyle = UIBarStyle.Black


来源:https://stackoverflow.com/questions/29274088/how-to-change-background-color-of-uisearchbar-to-black-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!