Dennis van Mazijk Dennis van Mazijk - 1 year ago 240
Swift Question

Swift - Scope buttons visible on top of UISearchBar

I created a search bar and a scope bar, but when the page launches the scope buttons are directly visible behind the search bar. I know that the .Minimal setting makes my search bar translucent, but it gives me a nice grey color that looks great on a white background.

Clicking on the search bar and then the cancel button will display everything correctly. The link below shows exactly what I am talking about.

UISearchBarStyleMinimal shows scope buttons on top of UISearchBar

Does anyone know how to fix this?


let searchController = UISearchController(searchResultsController: nil)

override func viewDidLoad() {

// Create search bar
self.searchController.searchResultsUpdater = self
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = true

self.definesPresentationContext = true
self.tableView.tableHeaderView = searchController.searchBar

self.searchController.searchBar.delegate = self
self.searchController.searchBar.scopeButtonTitles = ["All", "btn1", "btn2", "btn3"]

tableView.allowsMultipleSelectionDuringEditing = true


UISearchBar.appearance().searchBarStyle = .Minimal
UISearchBar.appearance().backgroundColor = UIColor.whiteColor()
UISearchBar.appearance().barTintColor = UIColor.whiteColor()
UISearchBar.appearance().tintColor = Constants.MAIN_THEME_COLOR

Answer Source

I had the same issue with my search but resolved it by adding this line:

self.searchController.searchBar.showsScopeBar = true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download