【发布时间】:2011-12-17 06:44:16
【问题描述】:
我想更改导航栏后退按钮的颜色,使其看起来像这样
【问题讨论】:
标签: ios cocoa-touch uinavigationbar back-button
我想更改导航栏后退按钮的颜色,使其看起来像这样
【问题讨论】:
标签: ios cocoa-touch uinavigationbar back-button
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];
试试这个它对我有用...
【讨论】:
我发现在全局或本地设置它的最佳方式是
[[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];
【讨论】:
如果你想让按钮看起来和你的图片一模一样,你也可以使用图片:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"back_button_bg"]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
为了获得良好的效果,背景图片必须是可调整大小的图片。
【讨论】:
jacob 回答的第一行对我不起作用,因为 backBarButtonItem 为 NULL。它是 NULL,因为它是稍后在切换到另一个 ViewController 时自动创建的。那时你可以用
设置按钮的标题self.title = @"nice title"; // self is here the view(controller) within the popoverController
但您不能设置 tintColor。
对我有用的是创建一个没有任何样式的新 UIBarButtonItem。然后设置title和color属性,设置为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];
【讨论】:
设置backBarButtonItem的tintColor:
self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor];
提示:如果您希望它默认应用于应用程序中的所有 UIBarButtonItem 实例,那么您可以使用新的UIAppearance API 来做就是这样:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
【讨论】: