iPhone设置背栏按钮项目的色调颜色

iPhone设置背栏按钮项目的色调颜色

本文介绍了iPhone设置背栏按钮项目的色调颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在导航控制器中设置后退按钮的色调颜色,但没有任何效果。我试过了

I am trying to set the tint color of the back button within a navigation controller, but nothing is working. I have tried

[self.navigationController.backBarButtonItem setTintColor:myColor];
//myColor was previously set

但它保持默认色调

推荐答案

我认为barButtonItem是只读的。 (我对此不太确定,如果我错了,有人会纠正我)

I believe barButtonItem is read-only. (I'm not too sure about this, someone correct me if I'm wrong)

要为这些按钮添加色彩,这就是我要做的:

To give a tint colour to these buttons, this is what I would do:

在您的App Delegate中,添加以下代码行:

In your App Delegate, add these lines of code:

UIBarButtonItem *barButtonAppearance = [UIBarButtonItem appearance];
[barButtonAppearance setTintColor:[UIColor redColor]]; // Change to your colour

第一行设置外观代理,所以我相信这也有效,如果你喜欢更少的代码:

The first line sets an appearance proxy, so I believe this works too, if you like less code:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

我希望这适合你! (这会更改UIBarButtonItem的所有实例)

I hope this works for you! (This changes all instances of UIBarButtonItem)

这篇关于iPhone设置背栏按钮项目的色调颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 09:22