【发布时间】:2021-10-10 02:57:12
【问题描述】:
在 iOS 15 的 SwiftUI 中使用新的 .searchable() 修饰符时,我无法自定义搜索栏的外观。具体来说,我不希望它与我用于导航栏的颜色相得益彰。
我尝试像这样更改.appearance()。
UISearchBar.appearance().backgroundColor = UIColor.white
UISearchBar.appearance().tintColor = UIColor.white
UISearchBar.appearance().barTintColor = UIColor.white
但只能设法得到这个。
即使这种成功,间距也不好看。我宁愿把它染成白色。
【问题讨论】:
-
你能提供一些额外的代码吗?例如,
ContentView中的代码?这是因为通过添加searchable()修饰符,TextField是透明的 -
您可以实现 init() 函数来初始化这些属性。当我使用 UINavigationBar.appearnce() 更改 tintColor 时,它实际上对我有用。但我仍在学习如何更改 textColor。
标签: swift search swiftui uisearchbar