LC 웃
LC 웃

Reputation: 18998

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

Upvotes: 6

Views: 10601

Answers (2)

Jay
Jay

Reputation: 1

Just in case someone is still struggling to stick search bar to dark mode, Just add this

self.navigationItem.searchController?.searchBar.overrideUserInterfaceStyle
= .dark

Upvotes: 0

dip
dip

Reputation: 3598

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

Upvotes: 8

Related Questions