fix: search bar cancel button may lost color issue

This commit is contained in:
CMK 2021-07-12 14:38:44 +08:00
parent fdf381a284
commit a41f1c2b5d
2 changed files with 5 additions and 10 deletions

View File

@ -157,12 +157,6 @@ extension SearchViewController {
view.bringSubviewToFront(statusBar)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
searchBar.tintColor = Asset.Colors.brandBlue.color
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
@ -182,8 +176,8 @@ extension SearchViewController {
searchBar.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
searchBar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
searchBar.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
searchBar.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
searchBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
searchBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
statusBar.translatesAutoresizingMaskIntoConstraints = false

View File

@ -62,9 +62,10 @@ final class ThemeService {
UITableViewCell.appearance().selectionColor = theme.tableViewCellSelectionBackgroundColor
// set search bar appearance
UISearchBar.appearance().barTintColor = theme.navigationBarBackgroundColor
UISearchBar.appearance().tintColor = Asset.Colors.brandBlue.color
UISearchBar.appearance().barTintColor = theme.navigationBarBackgroundColor
let cancelButtonAttributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.foregroundColor: Asset.Colors.brandBlue.color]
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(cancelButtonAttributes, for: .normal)
}
}