导航栏中的按钮颜色 - iPhone

时间:2009-08-27 12:05:00

标签: iphone uinavigationbar

如何将此黄色按钮的色调设置为灰色?我尝试过添加图像,但没有运气。

以下是截图:

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

6 个答案:

答案 0 :(得分:12)

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

答案 1 :(得分:5)

从iOS 5.0开始,您可以使用:

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

答案 2 :(得分: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];

答案 3 :(得分:3)

没有您的自定义图片是不可能的。

答案 4 :(得分:1)

实际上可以不使用按钮的图像。

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

答案 5 :(得分:0)

在导航栏中设置按钮图像时,您可能需要为其设置 UIImageRenderingModeAlwaysOriginal

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

这是reference