2009-08-27 188 views
9

如何將此黃色按鈕的色調設置爲灰色?我試圖添加一個圖像,但沒有運氣。導航欄中的按鈕顏色 - iPhone

下面是截圖:

alt text

這裏是我當前的代碼:

- (id)initWithStyle:(UITableViewStyle)style { 
    if (self = [super initWithStyle:style]) { 

     UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 
             initWithTitle:NSLocalizedString(@"Settings", @"") 
             style:UIBarButtonItemStyleDone 
             target:self 
             action:@selector(GoToSettings)]; 
     [addButton setImage:[[UIImage imageNamed:@"bg_table.png"] retain]]; 

     self.navigationItem.rightBarButtonItem = addButton; 
     self.navigationItem.hidesBackButton = TRUE; 
     self.view.backgroundColor = [UIColor blackColor]; 
    } 
    return self; 
} 

回答

3

這也不是沒有可能你的自定義圖像。

+1

是否可以給它一些顏色,例如灰色? – Mladen 2009-08-27 16:50:26

+1

addButton.tintColor = [UIColor grayColor]; – charliehorse55 2012-06-06 19:26:33

1

實際上,它可能不使用按鈕的圖像。

viewController.navigationController.navigationBar.tintColor = 
    [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.8]; 
+0

這改變了導航欄的顏色而不是按鈕。對於吉姆說的話, – 2011-06-27 12:49:48

+0

-1。 – 2011-11-16 18:34:40

+0

...但你可以通過這種方式設置按鈕色調,請參閱:http://stackoverflow.com/questions/8220715/how-to-set-custom-uinavigationbarbutton-color – 2011-11-22 01:08:12

4
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setBackgroundImage:[UIImage imageNamed:@"button_main.png"] 
             forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(GotoSettings) 
       forControlEvents:UIControlEventTouchUpInside]; 
button.frame = CGRectMake(x, y, x1, x2); 

UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:menu]; 
self.navigationItem.rightBarButtonItem = menuButton; 

[button release]; 
[menuButton release]; 
+0

我用這個,工作正常。 – ArunGJ 2011-05-29 00:42:39

+0

工作正常,但如何設置標題按鈕? – 2013-06-26 09:34:58

12
self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:0.1f green:0.66f blue:0.26f alpha:0.7]; 
5

從的iOS 5.0上,你可以使用:

[[UINavigationBar appearance] setTintColor:[UIColor yellowColor]]; 
0

當您設置在導航欄上的按鈕的圖像,你可能需要設置UIImageRenderingModeAlwaysOriginal爲它:

[addButton setImage:[[[UIImage imageNamed:@"bg_table.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] retain]]; 

這裏是reference