导航栏返回按钮的颜色

3

我无法更改导航栏返回按钮的颜色,可以帮忙吗?我已经自定义了UINavigationBar类,但是无法更改返回按钮的颜色。

UINavigationBar类代码
#import #import "UINavigationBar.h"
@interface UINavigationBar ( Category ) {
}
.m文件代码
- (void) drawRect:(CGRect)rect {
[[UIImage imageNamed:@"top.png"] drawInRect:rect]; self.tintColor = [UIColor colorWithRed:38 green:65 blue:82 alpha:1]; }

我无法更改返回按钮的颜色。

5个回答

9
使用这个方法,你可以改变所有导航按钮的颜色:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

将redColor替换为以下内容以调整按钮的颜色:

colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this.

注意:仅支持 iOS 5 及以上版本


如果我想为选定视图的返回按钮设置颜色怎么办? - Jayprakash Dubey
@JayprakashDubey 将此代码放入推送的视图控制器中,而不是您想要看到此返回按钮颜色的视图控制器中。 - SirRupertIII

2

使用此代码更改导航控制器中返回箭头的颜色

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed: 127.0/255.0f green:127.0/255.0f blue:127.0/255.0f alpha:1.0];

1
你需要使用一个带有自定义视图的UIBarButtonItem。就像这样:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
[button addTarget:target action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"back_button.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"back_button_tap.png"] forState:UIControlStateHighlighted];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

然后,您可以将按钮放置在导航栏中,通常在带有UINavigationController的控制器中:

self.navigationItem.leftBarButtonItem = buttonItem;

0
在Swift和iOS 7和8中,编写如下代码:
 self.navigationController.navigationBar.tintColor = UIColor.whiteColor() //<-- whiteColor is an example!!

0
在iOS7中,您应该通过更改按钮的颜色来进行替换。
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接