Search code examples
iosswiftstatusbar

Modal view status bar


enter image description here

I have created a modal segue which links from a view controller embedded in a navigation bar controller to a fresh new view controller which I have named "Search View Controller".

My problem is I can't seem to continue with the same red status bar as I had before. How can I change the status bar from white (nothing there) in the screenshot to red like the predecessor?

I have tried just simply adding a view with the red colour 20 pixels high which does work, but this hacky solution then creates problems when rotating to landscape.

Any ideas?


Solution

  • It's a pretty common problem, really. The only thing that worked for me was the hack found here: http://blog.ijasoneverett.com/2013/09/ios-7-bugs-the-status-bar-and-modal-view-controllers/ which is slightly (but not much more) elegant :)

    let fixItView = UIView()
    fixItView.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 20);
    fixItView.backgroundColor = UIColor.redColor() // your colour
    view.addSubview( fixItView )
    

    That's the basic idea. Try adding that small 'fixItView' to your navigation bar.