ios - 在 iOS 13 中使用 UISearchController 时,状态栏在 iOS 中变为白色
问题描述
这里有一个奇怪的情况。当我使用 时UISearchController
,我首先得到这个外观(如预期的那样)
但是,当您在 TextField 内选择开始搜索时,状态栏将变为完全白色(如果您处于暗模式,则为黑色)
这从来没有发生过。是否有一些设置UISearchController
告诉它在使用搜索栏时使用某种状态栏样式?
我希望它保持选择 TextField 之前的颜色
- -编辑 - -
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItem.Style.plain, target: nil, action: nil)
frc = getFRC()
frc.delegate = self
self.resultsSearchController.delegate = self
let searchBar = self.resultsSearchController.searchBar
self.resultsSearchController.searchResultsUpdater = self
self.resultsSearchController.obscuresBackgroundDuringPresentation = false
self.resultsSearchController.extendedLayoutIncludesOpaqueBars = true
searchBar.sizeToFit()
self.tableView.tableHeaderView = searchBar
searchBar.placeholder = "Catalog Search"
searchBar.barTintColor = UIColor.darkAqua
searchBar.searchTextField.backgroundColor = UIColor.white
self.definesPresentationContext = true
searchBarHeight = searchBar.frame.height
do {
try frc.performFetch()
} catch {
error.tryError(tryMessage: "Perform initial fetch", loc: self)
}
if tutorials.catalog {
createTutorialTab(segueNameOnOpen: "catalogTutorial")
}
}
解决方案
您可以使用此功能更改状态栏颜色,这是处理状态栏的一种技巧;)。如果您在整个应用程序中使用一个主题状态栏,请从 AppDelegate 中的 didFinishLaunching 调用此函数。
func changeStatusBar(backgroundColor: UIColor, contentColor:UIColor) {
if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
statusBar.backgroundColor = backgroundColor
statusBar.setValue(contentColor, forKey: "foregroundColor")
}
}
推荐阅读
- android - 两个应用程序(所有者和客户端)可以使用不同的身份验证空间共享同一个数据库吗?
- javascript - TypeORM - 获取用户时从不从数据库返回密码
- assembly - 检查一个数字(从 0 到 50)是否为素数
- php - NodeJS crypto.createHmac 的结果与 PHP 的 hash_hmac 不同
- python - 尽管安装了正确的依赖项,为什么 PyUSB 无法在 Windows 10 上运行?
- python - 如何解决调用 Python 对象时超出的最大递归深度
- python - 打印最后一行 Beautifulsoup
- javascript - 对对象数组中的参数值进行排序?
- azure - Azure Spring Cloud 和 JHipster
- c++ - 为接收字符数组编写 cin.get() 时出现问题