3

在 iOS6 中,我使用这段代码来制作我的 UIBarButtonItem:

UIBarButtonItem* validate = [[UIBarButtonItem alloc]initWithTitle:@"MyTitle" style:UIBarButtonItemStylePlain target:self action:@selector(actionValidate)];
    [validate setTintColor:[UIColor orangeColor]];
    self.navigationItem.rightBarButtonItem = validate;

它在 iOS6 中工作正常,但在 iOS7 中,按钮的颜色只有在你按下它时才会改变。我该如何解决这个问题?

4

2 回答 2

5

在 iOS7 中,如果您需要更改navigationBar按钮颜色,则必须设置tintColornavgationBar不再为特定的barButton

navigationController.navigationBar.tintColor = [UIColor orangeColor];

编辑:这适用于 iOS7,您需要进行检查:

float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
    navigationController.navigationBar.tintColor = [UIColor orangeColor]
}
于 2013-10-02T07:23:29.673 回答
2

我无法让@Chris 的方法起作用(@Adama 说的 iOS 8)。

我的用例是我想将所有UIToolbar&UINavigationBar按钮设置为默认颜色。所以使用UIAppearanceAPI​​:

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.redColor()], forState: .Normal)

于 2015-08-01T00:03:15.883 回答