From a41f1c2b5d042a7ff12c74577f979c6e813fd7ea Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 12 Jul 2021 14:38:44 +0800 Subject: [PATCH] fix: search bar cancel button may lost color issue --- Mastodon/Scene/Search/SearchViewController.swift | 10 ++-------- Mastodon/Service/ThemeService/ThemeService.swift | 5 +++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Mastodon/Scene/Search/SearchViewController.swift b/Mastodon/Scene/Search/SearchViewController.swift index f3638e58b..89b71f499 100644 --- a/Mastodon/Scene/Search/SearchViewController.swift +++ b/Mastodon/Scene/Search/SearchViewController.swift @@ -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 diff --git a/Mastodon/Service/ThemeService/ThemeService.swift b/Mastodon/Service/ThemeService/ThemeService.swift index 8a1b94179..c55000b8a 100644 --- a/Mastodon/Service/ThemeService/ThemeService.swift +++ b/Mastodon/Service/ThemeService/ThemeService.swift @@ -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) } }