Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of UiSearchBar to black -SWIFT

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)

figure 1

figure 2

like image 690
Anish Parajuli 웃 Avatar asked Mar 26 '15 08:03

Anish Parajuli 웃


1 Answers

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
like image 90
dip Avatar answered Oct 29 '22 22:10

dip