IOS 5如何更改导航栏中后退按钮的颜色?

我想更改导航栏后退按钮的颜色,使其看起来像这样 在此处输入图像描述

设置backBarButtonItemtintColor

 self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor]; 

提示 :如果您希望默认情况下将其应用于应用程序中的所有 UIBarButtonItem实例,则可以使用新的UIAppearance API执行此操作:

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

jacob的第一行答案对我不起作用,因为backBarButtonItem为NULL。 它为NULL,因为它在切换到其他ViewController时会自动创建。 那时你可以设置按钮的标题

 self.title = @"nice title"; // self is here the view(controller) within the popoverController 

但你不能设置tintColor。

对我有用的是创建一个没有任何风格的新UIBarButtonItem。 然后设置标题和颜色属性并将其设置为backBarButtonItem。

 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init]; backButton.title = @"go back - now!"; backButton.tintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0]; self.navigationItem.backBarButtonItem = backButton; [okButton release]; 

如果您想使按钮看起来与图片中的完全相同,您也可以使用图像:

 [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"back_button_bg"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

背景图像必须是可resize的图像才能获得良好效果。

我发现在全球或本地设置它的最佳方式是

  [[UIBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, nil] forState:UIControlStateNormal]; 
 [[UINavigationBar appearance]setTintColor:[UIColor whiteColor]]; 

试试这个对我有用……