我的UISearchBar设置如下:
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false // Allow user to tap on results
searchController.searchBar.placeholder = "Search patients" // Placeholder
searchController.searchBar.barStyle = .blackOpaque
searchController.searchBar.tintColor = colors.text // Cancel button tint
navigationItem.searchController = searchController // Set the searchController
navigationItem.hidesSearchBarWhenScrolling = true // Auto-hide search when user scrolls
Run Code Online (Sandbox Code Playgroud)
这是在iOS 12上的样子:
vs iOS 13:
iOS 13有什么变化?我试过了different barStyles,也将其设置.isTranslucent为false-均无效。亮/暗模式也不会更改任何内容。
另一个变化是隐藏了搜索栏-在iOS 12上,如果我向上滚动一点,搜索栏就会隐藏(无论表格是否填充)。在iOS 13中,一旦出现搜索栏(即用户向下滑动),就无法再次将其隐藏。有人也知道解决办法吗?
小智 21
我和你有类似的问题。我不知道为什么会在当前的 iOS 13 中发生这种情况并且在旧版本中正常工作。但是我通过将此功能添加到您的搜索栏中找到了解决方案。
if #available(iOS 13.0, *) {
searchBar.searchTextField.backgroundColor = UIColor.white
}
Run Code Online (Sandbox Code Playgroud)
修复后预览:
Tai*_* Le 10
如何使用searchBarStyleasdefault和更改searchTextField背景颜色?
if #available(iOS 13.0, *) {
searchBar.searchBarStyle = .default
searchBar.searchTextField.backgroundColor = UIColor.black.withAlphaComponent(0.1)
}
Run Code Online (Sandbox Code Playgroud)
对于全局设置,如 in AppDelegate:
if #available(iOS 13, *) {
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = .anyColor
}
Run Code Online (Sandbox Code Playgroud)
小智 4
searchController.searchBar.searchTextField.backgroundColor = UIColor.black作为解决方法来完成这项工作。选择器是 iOS 13 中的新增功能。
无论如何,我已经提交了一份关于反馈助理的报告,因为我确实认为这是意外行为。
| 归档时间: |
|
| 查看次数: |
1571 次 |
| 最近记录: |