简体   繁体   中英

Status Bar becomes white in iOS when using UISearchController in iOS 13

have a weird situation here. When I use the UISearchController , I get this appearance first (as expected)

在此处输入图像描述

But when you select inside the TextField to start searching, the Status Bar becomes completely white (or black if you are in dark mode)

在此处输入图像描述

This never used to happen. Is there some setting in UISearchController that tells it to use a certain Status Bar style when using the Search Bar?

I'd prefer it stay the color it was before selecting the TextField

---EDIT---

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")
    }
}

You use this function to change status bar colors, it's a kind of hack to deal with status bar;). If you are using one theme status bar in whole app, call this function from didFinishLaunching in AppDelegate.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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