2011-02-15 180 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!!