【问题标题】:Cannot change style of status bar无法更改状态栏样式
【发布时间】:2016-01-11 00:30:20
【问题描述】:

我在我的 iOS 应用程序中实现了一个导航栏,我将色调设置为白色,但是在运行应用程序时,状态栏不跟随色调,只是透明的(见图)。我的目标是让状态栏具有半透明的样式。

如何解决这个问题?

【问题讨论】:

标签: ios swift uinavigationbar


【解决方案1】:

要更改所有视图控制器中的状态栏颜色,请将其添加到您的 info.plist

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

然后清理并运行构建。

要设置特定于 ViewControllers 的状态栏颜色,请在 info.plist 中添加以下内容

<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

并且在 ViewController 的 viewDidLoad 方法中调用这个方法:

[self setNeedsStatusBarAppearanceUpdate];

并在 ViewController 中添加以下方法:

- (UIStatusBarStyle)preferredStatusBarStyle
{ 
    return UIStatusBarStyleLightContent; 
}

干杯:]

【讨论】:

  • 它只是将状态栏的文本设置为白色。还是透明的
  • 答案有多种,过一遍就好了。如果有任何帮助,请告诉我。 :)
  • 找到了罪魁祸首,我忘了我已将 navigationBar.layer.maskToBounds 设置为 true。现在它可以工作了。无论如何,谢谢你们!
【解决方案2】:

你已经试过了吗?

UIApplication.sharedApplication().statusBarStyle = .LightContent

【讨论】:

    【解决方案3】:

    试试这个

    [self setNeedsStatusBarAppearanceUpdate];//add it in view didload
    
    - (UIStatusBarStyle) preferredStatusBarStyle { 
            return UIStatusBarStyleLightContent; 
       }
    

    查看链接add the view in status bar 检查下一个 link

    【讨论】:

      猜你喜欢
      • 2017-12-13
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多