iOS 13 UISearchBar外观和行为

iOS 13 UISearchBar外观和行为,ios,swift,uisearchbar,ios13,Ios,Swift,Uisearchbar,Ios13,我的ui搜索栏设置如下: searchController.searchResultsUpdater = self searchController.obscuresBackgroundDuringPresentation = false // Allow user to tap on results searchController.searchBar.placeholder = "Search patients" // Placeholder searchController.searchB

我的
ui搜索栏设置如下:

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
这是iOS 12上的外观: 与iOS 13相比: iOS 13有什么变化?我尝试过使用不同的
barStyles
,并且还将
.isTranslucent
设置为false-这两种设置都没有效果。亮/暗模式也不会改变任何东西


另一个变化是隐藏搜索栏——在iOS 12上,如果我向上滚动一点,搜索栏就会隐藏(不管表格是否填充)。在iOS 13中,一旦搜索栏出现(即用户已向下滑动),它就无法再次隐藏。有人知道这个问题的解决方法吗?

searchController.searchBar.searchTextField.backgroundColor=UIColor.black
作为一种解决方法。选择器在iOS 13中是新的


我已经提交了一份关于反馈助手的报告,因为我确实认为这是意外行为。

如何使用
searchBarStyle
作为
default
并更改
searchTextField
背景色

if #available(iOS 13.0, *) {
    searchBar.searchBarStyle = .default
    searchBar.searchTextField.backgroundColor = UIColor.black.withAlphaComponent(0.1)
}

我对你也有类似的问题。我不知道为什么在目前的iOS 13中会发生这种情况,并且在旧版本中可以正常工作。但我已经找到了解决方案,将此功能添加到您的搜索栏中

if #available(iOS 13.0, *) {
   searchBar.searchTextField.backgroundColor = UIColor.white
}
修复后预览:


对于全局设置,如在
AppDelegate
中:

if #available(iOS 13, *) {
    UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = .anyColor
}
iOS 13+

searchController.searchBar.searchTextField.backgroundColor = UIColor.white

你有没有试过searchBar.searchBarStyle=.Profective???@Souviccse刚试过,没什么区别,不幸的是我已经放弃了大标题,而去搜索iOS 13了。这是一个巨大的集群(我很难在半透明的搜索栏上找到与iOS 13相同的外观。我最终得到了60行代码,用我自己的背景视图替换了原来的背景视图。@fl034看看我自己的答案。
UISearchBar.appearance().searchTextField.backgroundColor=.anyColor
在这里不起作用的原因是什么?