我想移除屏幕顶部的状态栏。

这行不通:

func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
        application.statusBarHidden = true
        return true
}

我也试过:

func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    var controller = UIViewController()
    application.statusBarHidden = true
    controller.setNeedsStatusBarAppearanceUpdate()

    var view = UIView(frame: CGRectMake(0, 0, 320, 568))
    view.backgroundColor = UIColor.redColor()
    controller.view = view

    var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
    label.center = CGPointMake(160, 284)
    label.textAlignment = NSTextAlignment.Center
    label.text = "Hello World"
    controller.view.addSubview(label)

    self.window!.rootViewController = controller
    self.window!.makeKeyAndVisible()
    return true
}

当前回答

Go to Info.plist file Hover on one of those lines and a (+) and (-) button will show up. Click the plus button to add new key Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY. Set the VALUE to "NO" Go to you AppDelegate.swift Add the code, inside the method func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool { application.statusBarHidden = true return true }

完成了!运行您的应用程序,没有更多的状态栏!

其他回答

斯威夫特3

在信息。plist设置基于控制器的状态栏外观为NO

调用uiapplication。shared。isstatusbarhidden = true

你真的应该在你的视图控制器上实现prefersStatusBarHidden:

Swift 3及后续版本

override var prefersStatusBarHidden: Bool {
    return true
}

转到你的信息。plist和添加两个键:

只是补充,当覆盖prefersStatusBarHidden方法或变量时,基于视图控制器的状态栏出现在信息中。plist必须为YES,否则重写将不起作用

对于Swift 4+,尝试以下代码(在Swift 4.0, 4.1 - IOS 10, 11上测试):

override var prefersStatusBarHidden: Bool { return true }

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    // call this func to force preferredStatusBarStyle to be read again.
    setNeedsStatusBarAppearanceUpdate()
}