如何在模态视图iOS 6上更改状态栏 [英] How to change Statusbar on Modal Views iOS 6

查看:205
本文介绍了如何在模态视图iOS 6上更改状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下星座:



主视图(自定义UIViewController,没有导航控制器或导航栏),包含一个按模块分段到第二个表视图控制器的按钮,它嵌入在导航控制器中:



MainView - >导航控制器 - > TableView



在MainView上状态栏为黑色(iOS 6无需更改 - 即使状态栏设置为默认值)
在TableViewController上,状态栏应具有默认样式(iOS 5中的灰色,iOS 6中的导航栏为蓝色) 。



在iOS 5中,通过TableViewController中的以下代码行很容易:

  if([[UIApplication sharedApplication] respondsToSelector:@ selector(setStatusBarStyle :)]){
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

在iOS 6下运行此注意事项。我怎样才能做到这一点?我在项目摘要和plist中尝试了所有可能的状态栏设置(如下所述:)



编辑:



要获得正确的颜色,您必须设置不可见UINavigationBar的tintColor。因此默认设置为黑色。在按钮操作中,您必须将tintColor设置为navigationController.navigationBar.tintColor。在关闭按钮的操作中,您需要将其设置回[UIColor blackColor]。


I have the following constellation:

Main View (Custom UIViewController, no navigationcontroller or navigation bar), containing a button which segues modally to a second Table view controller, which is embedded in a Navigation Controller:

MainView -> Navigation Controller -> TableView

On the MainView the status bar is Black (no changes with iOS 6 - even when Status Bar is set to Default) On the TableViewController the status bar should have Default Style (grey in iOS 5, Blue Tinted due to navigation bar in iOS 6).

In iOS 5 this was easy by the following lines of code in TableViewController:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarStyle:)]) {
   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

Running this under iOS 6 noting happens. How can I do this? I tried all possible Status Bar settings under project summary and in the plist (like described here: https://stackoverflow.com/a/12468689/1685971)

Also, in Storyboard everything looks fine. Running the app in simulator or on the device it looks different:

解决方案

try this "hack": You have to add a navigation bar to your first view controller. Then you have two possibilities.

1) Set the alpha value of the navigation bar to 0

or

2) Set the y-position of the bar to -43px (look here: http://moduscreate.com/tinting-your-status-bar-in-ios6-and-phonegap/)

EDIT:

To get the right colors you have to set the tintColor of the invisible UINavigationBar. So by default set it black. In your button action you have to set the tintColor to your navigationController.navigationBar.tintColor. At the action of your close button you need to set it back to [UIColor blackColor].

这篇关于如何在模态视图iOS 6上更改状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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