1
votes

I've tried to use all the properties UISearchBar has with different combinations, I've searched for the answer for a while but still can't solve the problem.

Problem: I have a UIViewController with UITableView in it and some other view in storyboard. I've added Search Bar and Screen Display Controller into my project (search bar is added as a subview/header of the UITableView)

I need to make it red color with no transparency/translucency to match my navigation bar.

I've tried "solution" from How to change background color of UISearchBar in iOS7 but it doesn't work. Result of this solution looks like that:

searchDisplayController?.searchBar.barTintColor = UIColor.myAppRedColor()
searchDisplayController?.searchBar.translucent = false

First solution

As you can see - that isn't exactly matching Navigation Bar color. It also has a separator between navbar and search bar.

Next solution almost worked:

searchDisplayController?.searchBar.backgroundImage = UIImage()
searchDisplayController?.searchBar.backgroundColor = UIColor.myAppRedColor()

Second solution, pic 1

But when I tap on the search bar it changes color:

Second solution, pic 2

It also has very weird animation: https://youtu.be/Dq1GKBGbmTc

Do you have an idea what else I can do instead of implementing my own SearchBar?

1
take a look please at my previous answer stackoverflow.com/a/45555462/3472073ale_stro

1 Answers

0
votes

Do not use Search Display Controller. Instead use only searchBar and TableView. Simply delete Search Display Controller from your storyboard. You will receive delegate methods of searchBar. Here you can apply search on tableView.