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

这行不通:

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
}

当前回答

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

其他回答

我使用的是Xcode 8.1 (8B62),部署目标设置为10.1,上面提到的覆盖选项我没有太多的运气。然而,检查部署信息中的“隐藏状态栏”选项对我来说是有用的。

项目>总则

我希望这能有所帮助。

斯威夫特3

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

调用uiapplication。shared。isstatusbarhidden = true

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

Swift 3及后续版本

override var prefersStatusBarHidden: Bool {
    return true
}

你可以在你的ViewController类范围内使用这段代码

open override var prefersStatusBarHidden: Bool { return true }

更新为iOS 13和Swift 5

如果以上答案都不适合你。检查你的plist,看看你是否有这个:

“基于视图控制器的状态栏外观”

如果是,请确保将其设置为YES!!!!!

然后下面的代码将工作。

override var prefersStatusBarHidden: Bool {
    return true
}