如何在Swift iOS应用程序中隐藏状态栏?

前端之家收集整理的这篇文章主要介绍了如何在Swift iOS应用程序中隐藏状态栏?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想删除屏幕顶部的状态栏。

这不工作:

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,320,568))
    view.backgroundColor = UIColor.redColor()
    controller.view = view

    var label = UILabel(frame: CGRectMake(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
}
你真的应该实现prefeRSStatusBarHidden在你的视图控制器:

swift 2

override func prefeRSStatusBarHidden() -> Bool {
    return true
}

swift 3

override var prefeRSStatusBarHidden: Bool {
    return true
}

猜你在找的Swift相关文章