2

I have a UISearchController in my view controller, when the searchBar is active the status bar becomes transparent. I've tried this and this but none of them worked.

enter image description here

This is the view hierarchy of the view controller:

enter image description here

How can I make the status bar translucent?

Community
  • 1
  • 1
Maysam
  • 7,246
  • 13
  • 68
  • 106

1 Answers1

1

Using this in viewDidLoad solved the problem:

var frame = UIApplication.shared.statusBarFrame
        frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height*3.3)
//3.3 is a practical number
        let statusBarView = UIView(frame: frame)
        statusBarView.backgroundColor = sharedApplication.mainThemeColor
        searchController.view.addSubview(statusBarView)
Maysam
  • 7,246
  • 13
  • 68
  • 106
  • Thanks! Worked for me without multiplying by `3.3` and I also used `statusBarView.backgroundColor = searchController.view.backgroundColor` to make sure they have the same color. – Ivan Mir Oct 10 '20 at 16:33