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

标签 ios iphone ios7 swift

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

这不起作用:

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
}

最佳答案

你真的应该在你的 View Controller 上实现 prefersStatusBarHidden:

Swift 3 及更高版本

override var prefersStatusBarHidden: Bool {
    return true
}

关于ios - 如何在 Swift iOS 应用程序中隐藏状态栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24236912/

相关文章:

iphone - IPhone 上的 "unsigned int"和 "int"在性能方面有区别吗?

iphone - 使用自定义形状的孔创建图层蒙版

iPhone - 将字符串截断到最后四位

xcode - iOS 7 状态栏和 self.view.frame 和 self.view.bounds

ios - 如何获得 UIWebView 的 iOS 8 系统字体的等效字体?

javascript - 是否可以使用 Expo 将文件写入 iOS 文件系统,以便可以通过 iOS 11 文件应用程序访问该文件

ios - 让用户使用 parse.com 的云代码关闭不同的通知类型

ios - 使用 AVPlayer 实现流畅的视频擦洗

cocos2d-iphone - Assets 目录可以消除 Sprite 表中 iOS 设备资源扩展的需要吗?

ios - 我怎样才能实现这样的目标?