ios - 在iOS 13中使用UISearchController时,状态栏在iOS中变为白色

标签 ios swift uisearchcontroller

这里有一个奇怪的情况。当我使用UISearchController时,我首先得到了这种外观(如预期的那样)

enter image description here

但是,当您在TextField中选择开始搜索时,状态栏将变为完全白色(如果处于黑暗模式则为黑色)

enter image description here

这从未发生过。 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")
    }
}

关于ios - 在iOS 13中使用UISearchController时,状态栏在iOS中变为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58311729/

相关文章:

iOS 应用程序每次都会收到新的 APNS 设备 token

swift - 通过按钮在新的 Web View 中打开 PDF 文件

ios - 如何在数组中的每 3 个对象之后添加数组中的对象?

iOS 13 如何在导航栏中隐藏 UISearchController searchBar

ios - Xcode6.3部署目标错误

ios - UINavigationController deinit 从未调用过

ios - Facebook SDK-FBSession : No AppID provided

ios - 无法将 searchBar 设置为 firstResponder

ios - 使 UISearchBar 不像在联系人应用程序中那样滚动

ios - 有没有办法检测 iPhone 是否处于反色模式?