9

この黄色のボタンの色合いを灰色に設定するにはどうすればよいですか?画像を追加してみましたが、うまくいきませんでした。

スクリーンショットは次のとおりです。

代替テキスト

これが私の現在のコードです:

- (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;
}
4

6 に答える 6

12
self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:0.1f green:0.66f blue:0.26f alpha:0.7];
于 2012-04-19T06:14:52.347 に答える
5

iOS 5.0以降では、次のものを使用できます。

    [[UINavigationBar appearance] setTintColor:[UIColor yellowColor]];
于 2012-06-26T23:45:41.390 に答える
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];
于 2010-06-03T04:30:34.973 に答える
3

カスタム画像なしでは不可能です。

于 2009-08-27T14:56:44.353 に答える
1

実はボタンに画像を使わなくても可能です。

viewController.navigationController.navigationBar.tintColor = 
    [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.8];
于 2009-12-31T06:45:10.983 に答える
0

ナビゲーションバーでボタンの画像を設定するときは、UIImageRenderingModeAlwaysOriginalを設定することをお勧めします。

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

これがリファレンスです。

于 2014-07-08T08:32:07.170 に答える