为什么tintColor不能在iOS7上的导航栏或工具栏上工作 [英] why tintColor doesnt't work on navigation bar or toolbar on iOS7

查看:102
本文介绍了为什么tintColor不能在iOS7上的导航栏或工具栏上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 navigationn 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 naviagtion bar and tool bar.

我尝试使用导航栏和工具的 barTintColor 属性吧,它有效。

I have tried with the barTintColor property of navigation bar and tool bar, it works.

我不知道会发生什么,以及如何修复它。

I don't know what happens, and how to fix it.

请求助!谢谢!

更新

首先,我定义了一个视图控制器: modalViewController
目前的模态视图控制器如下:

first, I define a view controller: modalViewController The 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
像这样呈现导航控制器: / p>

Second, define a navigation view controller: navigationController Present 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.

默认情况下,当导航视图控制器出来时,所有工具栏按钮项目(这些项目仅使用基本标题构建,如取消确定)变为灰色。

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 工具栏导航栏。使用实例方法和外观方法(如 [[UIToolBar外观] 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 $ c>直接来自普通视图控制器的样式,然后导航栏和工具栏的所有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假设我们不会提供多个视图控制器并使背景和所有条形按钮项目变暗(不确定原因)作为将焦点放在最前面的视图上的默认行为。

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上的导航栏或工具栏上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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