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

这行不通:

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
}

当前回答

斯威夫特3

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

调用uiapplication。shared。isstatusbarhidden = true

其他回答

如果你更喜欢可视化的方法而不是编码,请使用以下方法: 在你的info.plist

简单地添加基于视图控制器的状态栏外观为NO

和状态栏最初隐藏为YES

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

项目>总则

我希望这能有所帮助。

在Swift 3.x:

override func viewWillAppear(_ animated: Bool) {
    UIApplication.shared.isStatusBarHidden = true
}

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

iOS 10 / Swift 3.0更新

不再是函数,现在是属性…

override var prefersStatusBarHidden: Bool {
    return true
}