Jon*_*gel 8 search uisearchbar swift swiftui
在 iOS 15 上的 SwiftUI 中使用新.searchable()修饰符时,我无法自定义搜索栏外观。具体来说,我不希望它与我用于导航栏的颜色看起来很好。
我尝试.appearance() 像这样改变。
UISearchBar.appearance().backgroundColor = UIColor.white
UISearchBar.appearance().tintColor = UIColor.white
UISearchBar.appearance().barTintColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
但只设法得到了这个。
尽管这种方式很成功,但间距看起来并不好。我宁愿把它染成白色。
Jon*_*gel 10
我通过使用这两条全局外观线解决了这个问题。
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = .white
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .black
Run Code Online (Sandbox Code Playgroud)