Swift - 更改范围栏色调颜色

时间:2017-11-10 03:19:28

标签: ios swift uisearchbar

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

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

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

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

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

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

search scope red tint color