导航栏中的按钮颜色 - iPhone
如何将此黄色按钮的色调设置为灰色?我试图添加一个图像,但没有运气。导航栏中的按钮颜色 - iPhone
下面是截图:
这里是我当前的代码:
- (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;
}
这也不是没有可能你的自定义图像。
实际上,它可能不使用按钮的图像。
viewController.navigationController.navigationBar.tintColor =
[UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.8];
这改变了导航栏的颜色而不是按钮。对于吉姆说的话, – 2011-06-27 12:49:48
-1。 – 2011-11-16 18:34:40
...但你可以通过这种方式设置按钮色调,请参阅:http://stackoverflow.com/questions/8220715/how-to-set-custom-uinavigationbarbutton-color – 2011-11-22 01:08:12
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];
我用这个,工作正常。 – ArunGJ 2011-05-29 00:42:39
工作正常,但如何设置标题按钮? – 2013-06-26 09:34:58
self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:0.1f green:0.66f blue:0.26f alpha:0.7];
从的iOS 5.0上,你可以使用:
[[UINavigationBar appearance] setTintColor:[UIColor yellowColor]];
当您设置在导航栏上的按钮的图像,你可能需要设置UIImageRenderingModeAlwaysOriginal为它:
[addButton setImage:[[[UIImage imageNamed:@"bg_table.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] retain]];
这里是reference。
是否可以给它一些颜色,例如灰色? – Mladen 2009-08-27 16:50:26
addButton.tintColor = [UIColor grayColor]; – charliehorse55 2012-06-06 19:26:33