Search code examples
swiftuiviewuistatusbar

Position UIView above status bar


I am trying to get a UIView to sit on top of the status bar, but currently have had no success. I have tried the following:

view.window?.windowLevel = UIWindowLevelStatusBar + 1 // view being a UIView() object

I have also tried:

let win: UIWindow = UIWindow( )
win.frame = CGRect( x: 0, y: 0, width: 100, height: Display.height )
win.windowLevel = UIWindowLevelStatusBar + 1
win.hidden = false
win.backgroundColor = UIColor.blueColor()
win.makeKeyAndVisible()

In all cases the status bar is still on top. Has anyone got this to work in Swift yet?


Solution

  • Why don't you hide the status bar? Then you can put the view at the top. See How to hide iOS status bar.

    I don't think it is possible to cover the status bar with another view, because all content is behind the status bar by default.