[英]How to change searchable search icon color in swiftui
I want to change the search icon color.我想更改搜索图标的颜色。 is there a way to change it?
有没有办法改变它?
NavigationView {
Text("Searching for \(searchText)")
.searchable(text: $searchText, prompt: "Look for something")
.foregroundColor(.red)
.navigationTitle("Searchable Example")
}
Yes there is a way.是的,有办法。 Basically you have to create your own magnifying glass.
基本上你必须创建自己的放大镜。
Below code you would typically put into a class function and call it when the view appears.下面的代码您通常会放入 class function 并在视图出现时调用它。
UISearchBar.appearance().setImage(searchBarImage(), for: .search, state: .normal)
private func searchBarImage() -> UIImage {
let image = UIImage(systemName: "magnifyingglass")
return image!.withTintColor(UIColor(.red), renderingMode: .alwaysOriginal)
}
IF this is not what you're looking for, then look into UISearchBar.appearance() properties, you can change lots of things through it.如果这不是您要查找的内容,请查看 UISearchBar.appearance() 属性,您可以通过它更改很多内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.