无法在 Objective C 中更改导航栏文本颜色或色调颜色

Not able to change navigationbar text color or tint color in Objective C

我想同时设置导航栏背景颜色和导航色调颜色,这样我就可以设置导航栏中所有系统按钮的色调颜色。我写了下面的代码:

NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[ver objectAtIndex:0] intValue] >= 7) {
    // iOS 7.0 or later
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    self.navigationController.navigationBar.translucent = NO;
}else {
    // iOS 6.1 or earlier
    self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
}
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];

此代码仅更改导航栏的背景颜色,但不更改按钮的色调。按钮以默认蓝色显示。但是在导航到其他屏幕时,有时按钮颜色会更改为我通过上面的代码设置的颜色,但这并不总是发生。

这肯定有效,在 Appdelegate 中调用它

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];