问题描述
在iPad的iOS7上,首先,我设置了一个模态视图控制器,大小为320 * 460,然后,在此模态视图控制器中,我展示了另一个导航视图控制器,其后是导航栏和工具的色调所显示的导航控制器的条变为灰色.我试图设置导航栏和工具栏的颜色,但这是行不通的.
On iOS7 of iPad, first, I setup an modal view controller, the size is 320 * 460, then, in this modal view controller, I presented another navigation view controller, after this, the tint color of navigation bar and tool bar of the presented navigation controller turns gray. I have tried to set tint color of navigation bar and tool bar, but it just doesn't work.
然后我尝试直接显示导航控制器,然后所有色调都可以在导航栏和工具栏上使用.
Then I tried to present the navigation controller directly, then all tint color works both on navigation bar and tool bar.
我尝试使用导航栏和工具栏的barTintColor
属性,它可以正常工作.
I have tried with the barTintColor
property of navigation bar and tool bar, it works.
我不知道会发生什么.
更新
首先,我定义一个视图控制器:modalViewController当前的模态视图控制器是这样的:
first, I define a view controller: modalViewControllerThe present the modal view controller like this:
if (DeviceIsPad()) // DeviceIsPad is a method defined somewhere to tell that the device is an iPad.
modaViewController.modalPresentationStyle = UIModalPresentationFormSheet;
//here self is a normal view controller
[self presentViewController:modalViewController animated:YES completion:NULL];
第二,定义一个导航视图控制器:navigationController像这样显示导航控制器:
Second, define a navigation view controller: navigationControllerPresent the navigation controller like this:
if (DeviceIsPad())
navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
// here self means the modalViewController mentioned above
[self presentViewController:navigationController animated:YES completion:nil];
我在navigationController的'viewDidLoad'方法中设置了导航栏和工具栏栏项.
I setup the navigation bar and toolbar bar items in 'viewDidLoad' method of navigationController.
默认情况下,当导航视图控制器出现时,所有工具栏按钮项(这些项仅以诸如Cancel
,OK
之类的基本标题构建)变成灰色.
By default, when the navigation view controller comes out, all toolbar button items(The items are built with just basic title like Cancel
, OK
) turns to be gray.
同时,我尝试将tintColor
设置为tool bar
和navigation bar
.实例方法和外观方法(如[[UIToolBar appearance] setTintColor:[UIColor blueColor]]
)都被使用.但这仍然行不通.
At the same time, I have tried to set tintColor
of tool bar
and navigation bar
. Both instance method and appearance method(like [[UIToolBar appearance] setTintColor:[UIColor blueColor]]
) are used. But it still doesn't work.
然后我尝试直接从普通视图控制器中以UIModalPresentationFormSheet
样式呈现上述的navigationViewController
,然后导航栏和工具栏的所有tintColor都变为蓝色(系统蓝色).
And then I tried to present the navigationViewController
mentioned above with UIModalPresentationFormSheet
style directly from a normal view controller, then all tintColor for navigation bar and tool bar turns to be the blue color(the system blue color).
推荐答案
之所以会发生这种情况,是因为Apple假定我们不会提供超过1个视图控制器,并且将背景和所有长条按钮项(不确定原因)变暗为默认行为将焦点放在最前面的视图上.
This happens because Apple assumes that we won't present more than 1 view controller and dims the background and ALL bar button items (not sure why) as default behavior to put focus on the frontmost view.
要解决此问题,只需在DidFinishLaunchingWithOptions中在应用程序窗口上将tintAdjustmentMode强制为Normal.
To fix this, you just need to force the tintAdjustmentMode to Normal on the app's window in DidFinishLaunchingWithOptions.
self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
这篇关于为什么tintColor在iOS7的导航栏或工具栏上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!