繁体   English   中英

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

[英]Status Bar becomes white in iOS when using UISearchController in iOS 13

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

在此处输入图像描述

但是当你在 TextField 里面的 select 开始搜索时,状态栏变成完全白色(如果你在黑暗模式下,状态栏变成黑色)

在此处输入图像描述

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

你用这个 function 来改变状态栏 colors,这是处理状态栏的一种 hack;)。 如果您在整个应用程序中使用一个主题状态栏,请从 AppDelegate 中的 didFinishLaunching 调用此 function。

func changeStatusBar(backgroundColor: UIColor, contentColor:UIColor) {

    if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
        statusBar.backgroundColor = backgroundColor
        statusBar.setValue(contentColor, forKey: "foregroundColor")
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM