Fine Man
Fine Man

Reputation: 465

Swift/iOS 8, Status bar is not hidden when prefersStatusBarHidden() is set to true

I have the following setting in a iOS app project: "Hide status bar" is not checked.

It can be found in the general project settings under deployment info.

In AppDelegate.swift:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        window = UIWindow(frame: UIScreen.mainScreen().applicationFrame)

        window!.rootViewController = ViewController()
        window!.makeKeyAndVisible()
        // Override point for customization after application launch.
        return true
    }
...

In ViewController.swift:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        view.backgroundColor = UIColor.blueColor()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prefersStatusBarHidden() -> Bool {
        return true;
    }
}

I got the following result (unfortunately, I'm a new member and don't have enough rep. to post images): Most of the screen is blue, except the very top (where the status bar should show), which is black.

Can anyone explain to me why the top is black, and how to fix it (e.g. turn it into blue)?

Upvotes: 2

Views: 1341

Answers (1)

matt
matt

Reputation: 535138

The top is black because this line is wrong:

window = UIWindow(frame: UIScreen.mainScreen().applicationFrame)

It should be:

window = UIWindow(frame:UIScreen.mainScreen().bounds)

Upvotes: 2

Related Questions