但普通视图控制器是正确的

但普通视图控制器是正确的

本文介绍了iOS 7:模态视图控制器状态栏颜色错误,但普通视图控制器是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在iOS7中遇到一个问题,普通的UINavigationController推送视图控制器具有UINavigationController导航栏颜色的正确状态栏文本颜色(浅灰色,几乎为白色,因此状态栏文本为黑色)。但是,当使用 -presentViewController:animated:completion:呈现模态视图控制器时,状态栏文本颜色将更改为白色,并且很难看到给定导航栏的颜色。 Navbar颜色在整个应用程序中始终相同,并且不会针对每个视图控制器进行更改。这发生在每个 -presentViewController 调用。

I have an issue in iOS7 where a normal UINavigationController pushed view controller has the correct status bar text color for the UINavigationController navbar color (which is a light gray, almost white so the status bar text is black). However, when a "modal" view controller is presented using -presentViewController:animated:completion:, the status bar text color is changed to white and is very hard to see given the color of the navbar. Navbar color is always the same across the whole app and does not change for each view controller. This happens on every -presentViewController call.

查看基于控制器的状态栏外观设置为YES。

"View controller-based status bar appearance" is set to YES.

我不知道该尝试解决这个问题。

I am not sure what to look at to try and solve this.

推荐答案

导航控制器根据导航栏的 barStyle 属性决定是否拥有浅色或深色内容。默认值 UIBarStyleDefault 表示导航栏颜色浅,状态栏颜色较暗。将此属性更改为 UIBarStyleBlack 实际上不会使导航栏变黑(导航栏的颜色仍然使用 barTintColor ),但它告诉它它有一个深色。导航控制器然后决定,由于导航栏是黑暗的,它应该将状态栏内容设置为亮。

The navigation controller decides whether to have a light or dark content based on its navigation bar's barStyle property. The default, UIBarStyleDefault, means the navigation bar has a light color and the status bar will have dark content. Changing this property to UIBarStyleBlack doesn't actually make the navigation bar black (the color of the navigation bar is still set using barTintColor), but it tells it that it has a dark color. The navigation controller then decides that, since the navigation bar is dark, it should set the status bar content to light.

它显示在您的主导航控制器上(在其上)你推送的东西) barStyle 确实设置为 UIBarStyleBlack 某处。您必须对模态提供的导航控制器执行相同的操作,如下所示:

It appears that on your main navigation controller (on which you push things) the barStyle is indeed set to UIBarStyleBlack somewhere. You have to do the same thing to the modally presented navigation controller, like so:

UINavigationController *newViewController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
newViewController.navigationBar.barStyle = self.navigationController.navigationBar.barStyle;
[self presentViewController:newViewController animated:YES completion:nil];

这篇关于iOS 7:模态视图控制器状态栏颜色错误,但普通视图控制器是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:22