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

发布于 2024-12-12 07:01:28 字数 89 浏览 0 评论 0原文

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

I want to change the color of back button of a navigation bar to make it look like thisenter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一念一轮回 2024-12-19 07:01:29

设置 backBarButtonItemtintColor

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

提示:如果您希望将其应用于所有 UIBarButtonItem默认情况下,您的应用程序中存在 实例,那么您可以使用新的 UIAppearance API 来做到这一点:

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

Set the backBarButtonItem's tintColor:

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

TIP: If you want this to be applied to all UIBarButtonItem instances in your application by default, then you can use the new UIAppearance API to do just that:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
赏烟花じ飞满天 2024-12-19 07:01:29

雅各布答案的第一行对我不起作用,因为 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];

The first line of jacob's answer didn't work for me because the backBarButtonItem was NULL. It is NULL because it's been created later automatically when switching to an other ViewController. At that time you can set the title of the button with

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

but you can't set the tintColor.

What worked for me, was to create a new UIBarButtonItem without any style. Then set the title and color propertys and set it as 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];
沫尐诺 2024-12-19 07:01:29

如果您想让按钮看起来与图片中的一模一样,您也可以使用图像:

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

背景图像必须是可调整大小的图像才能获得良好的效果。

If you want to make the button look exactly like in your picture, you may use an image, too:

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

The background image must be a resizable image for good results.

输什么也不输骨气 2024-12-19 07:01:29

我发现全局或本地设置它的最佳方法是

    [[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];

Best way I found to set it globally or locally is

    [[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];
棒棒糖 2024-12-19 07:01:29
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];

试试这个它对我有用......

[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];

try this It is working for me...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文