Swift - 更改范围栏色调颜色

时间:2022-09-17 21:34:22

I created a search controller with a scope bar programmatically and I couldn't change the scope bar's tint color. I created the search controller with the following code:

我以编程方式创建了一个带有范围栏的搜索控制器,但我无法更改范围栏的色调颜色。我使用以下代码创建了搜索控制器:

searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Buildings or Codes"
navigationItem.searchController = searchController
definesPresentationContext = true
searchController.searchBar.scopeButtonTitles = ["Building Names", "Building Codes"]
searchController.searchBar.delegate = self

There is also a cancel button for the search bar and I changed the tint color using this code:

搜索栏还有一个取消按钮,我使用以下代码更改了色调颜色:

UIBarButtonItem.appearance(whenContainedInInstancesOf:[UISearchBar.self]).tintColor = UIColor.red

Thank you so much for your help.

非常感谢你的帮助。

1 个解决方案

#1


2  

let darkRed = UIColor(red: 0.392, green: 0.012, blue: 0.020, alpha: 1.00)
searchController.searchBar.tintColor = darkRed

Swift  - 更改范围栏色调颜色

#1


2  

let darkRed = UIColor(red: 0.392, green: 0.012, blue: 0.020, alpha: 1.00)
searchController.searchBar.tintColor = darkRed

Swift  - 更改范围栏色调颜色