如何在 Swift iOS 应用程序中隐藏状态栏? [英] How do I hide the status bar in a Swift iOS app?

查看:40
本文介绍了如何在 Swift iOS 应用程序中隐藏状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to remove the status bar at the top of the screen.

这不起作用:

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
}

推荐答案

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

You really should implement prefersStatusBarHidden on your view controller(s):

Swift 3 及更高版本

override var prefersStatusBarHidden: Bool {
    return true
}

这篇关于如何在 Swift iOS 应用程序中隐藏状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆