2009-08-27 9 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

+1

addButton.tintColor = [UIColor grayColor]; – charliehorse55

1

実際にボタン用の画像を使用せずに可能です。 iOSの5.0および使用することができます上から

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

これは、ボタンの代わりにナビゲーションバーの色を変更します。ジムが言ったことのために –

+0

-1。 –

+0

...ボタンの色をこのように設定することができます:http://stackoverflow.com/questions/8220715/how-to-set-custom-uinavigationbarbutton-color –

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

+0

正常に動作しますが、タイトルをボタンに設定するにはどうすればよいですか? –

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

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

あなたはナビゲーションバーのボタンのイメージを設定すると、あなたがUIImageRenderingModeAlwaysOriginalを設定することもできますそれ:

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

referenceです。

関連する問題