Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status bar changes color when searching

Tags:

ios

swift

iphone

I'm using a UISearchController that, when clicked, makes the navigation bar rise and turn the status bar white. I want the status bar to remain green.

My UISearchController implementation:

self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.searchBar.placeholder = "Pesquisa por linha ou cod..."
        controller.searchBar.tintColor = UIColor(netHex: 0xFFFFFF)
        controller.searchBar.barTintColor = UIColor(netHex: 0x2F7C30)
        controller.searchBar.clipsToBounds = true
        controller.searchBar.layer.borderWidth = 1;
        controller.searchBar.layer.borderColor = UIColor(netHex: 0x2F7C30).CGColor
        self.navigationController!.view.backgroundColor = UIColor(netHex: 0x2F7C30)

        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()

Before clicking on the search bar Before clicking on the search bar

After clicking on the search bar After clicking on the search bar

like image 362
Marcio Granzotto Avatar asked Aug 26 '15 19:08

Marcio Granzotto


2 Answers

Playing off of Daniel Storm's response. Adding the subview to the UISearchController's view solved the issue for me.

let statusBarView = UIView(frame: CGRectMake(0, 0,
    UIApplication.sharedApplication().statusBarFrame.size.width,
    UIApplication.sharedApplication().statusBarFrame.size.height))
statusBarView.backgroundColor = Colors.Primary.Regular
searchController.view.addSubview(statusBarView)
like image 107
Michael Thomas Avatar answered Oct 17 '22 16:10

Michael Thomas


Put a UIView behind your status bar with the background color you need.

let statusBarView = UIView(frame: UIApplication.sharedApplication().statusBarFrame)
statusBarView.backgroundColor = UIColor.greenColor() // Replace with color you desire
view.addSubview(statusBarView)
like image 36
Daniel Storm Avatar answered Oct 17 '22 16:10

Daniel Storm