问题
Hi I have setup search controller using
private func setupSearchbar() {
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Contacts"
self.navigationItem.searchController = searchController
self.definesPresentationContext = true
}
Everything was working fine until I add this code
UINavigationBar.appearance().isOpaque = true
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = UIColor(named: "PrimaryDark")
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 22) ,NSAttributedString.Key.foregroundColor:UIColor.white]
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 34) ,NSAttributedString.Key.foregroundColor:UIColor.white]
Now When I tap on search bar big bottom black bar appears
How to fix this ?
View Debugging
回答1:
Okay So I am able to fix this issue. I am sharing this so this might helpful to other facing the same issue.
to fix this issue. In view will appear method I have set self.extendedLayoutIncludesOpaqueBars
to true
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.extendedLayoutIncludesOpaqueBars = true
}
Hope it helps to someone :)
Here is output
回答2:
Remove this
UINavigationBar.appearance().isOpaque = true
UINavigationBar.appearance().isTranslucent = false
来源:https://stackoverflow.com/questions/56250292/search-controller-in-navigation-item-show-black-bar