使用Swift隐藏iOS App中的状态栏?


有时在我们的应用程序中,我们需要隐藏状态栏、导航栏和其他内容,只显示我们想要显示的内容。在这篇文章中,我们将了解如何在我们的应用程序中隐藏状态栏。要使用Swift语言隐藏iOS应用程序中的状态栏,我们需要经历一些非常基本的步骤。

我们可以通过两种常见方法隐藏状态栏。这两种方法都包含一个共同的步骤。

共同步骤

  • 转到您的info.plist文件。
  • 添加一个名为“View controller-based status bar appearance”的键,并将它的值设置为NO。

这是我们在下面提到的两种方法中都会使用到的一个共同步骤,它还包含一个额外的步骤。

方法1

在您的info.plist文件中,添加另一个名为“Status bar is initially hidden”的键,并将它的值设置为YES。

方法2

  • 转到您的应用程序委托文件。
  • 在app did finish launching方法内部添加一行代码。
UIApplication.shared.isStatusBarHidden = true

这将隐藏整个应用程序中的状态栏。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
   // Override point for customization after application launch.
   // UIApplication.shared.isStatusBarHidden = true
   return true
}

上述两种方法产生相同的结果,即:

更新于:2019年7月30日

2K+ 浏览量

启动你的职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.