Reputation: 205
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?
SearchController.swift
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
// Create search bar
self.searchController.searchResultsUpdater = self
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = true
self.searchController.searchBar.sizeToFit()
self.definesPresentationContext = true
self.tableView.tableHeaderView = searchController.searchBar
self.searchController.searchBar.delegate = self
self.searchController.searchBar.scopeButtonTitles = ["All", "btn1", "btn2", "btn3"]
tableView.allowsMultipleSelectionDuringEditing = true
}
AppDelegate.swift
UISearchBar.appearance().searchBarStyle = .Minimal
UISearchBar.appearance().backgroundColor = UIColor.whiteColor()
UISearchBar.appearance().barTintColor = UIColor.whiteColor()
UISearchBar.appearance().tintColor = Constants.MAIN_THEME_COLOR
Upvotes: 1
Views: 2591
Reputation: 86
I had the same issue with my search but resolved it by adding this line:
self.searchController.searchBar.showsScopeBar = true
Upvotes: 6