2011-02-15 327 views
3

我无法更改导航栏后退按钮的颜色。任何帮助?我自定义了UINavigationBar类,但我无法更改后退按钮的颜色。导航栏后退按钮颜色

UINavigationBar class code 

#import 
#import "UINavigationBar.h" 

@interface UINavigationBar (Category) 
{ 

} 

.m file code 

- (void) drawRect:(CGRect)rect 
{ 

    [[UIImage imageNamed:@"top.png"] drawInRect:rect]; 
    self.tintColor = [UIColor colorWithRed:38 green:65 blue:82 alpha:1];  
}

我无法更改后退按钮的颜色。

回答

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; 
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和>

+0

+ 1谢谢你!!!其工作 – 2013-03-01 13:09:46

0

在iOS7,你应该

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

使用替换按钮的颜色这种变革后退箭头颜色导航控制器

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

在swift和iOs 7和8中写道:

self.navigationController.navigationBar.tintColor = UIColor.whiteColor() //<-- whiteColor is an example!!