Maysam
Maysam

Reputation: 7367

statusBar becomes transparent when searchBar is active

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?

Upvotes: 2

Views: 480

Answers (1)

Maysam
Maysam

Reputation: 7367

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)

Upvotes: 1

Related Questions