我有一个应用程序,我正在创建一个工具栏来浏览Web视图。除了按钮的颜色外,一切正常。当我没有启用按钮时,它显示的颜色与工具栏的色调。当我启用它时它显示为白色。但我需要按原样显示按钮。我是怎么做的,`
[self.navigationController setToolbarHidden:NO animated:YES];
self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;
self.navigationController.toolbar.tintColor=[UIColor colorWithRed:215/255.0 green:215/255.0 blue:215/255.0 alpha:1.0];
buttonGoBack = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTouchUp:)];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpace.width = 30;
buttonGoForward = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(forwardButtonTouchUp:)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
buttonAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(buttonActionTouchUp:)];
UIBarButtonItem *buttonContainer = [[UIBarButtonItem alloc] initWithCustomView:containerView];
[containerView release];
NSMutableArray *toolBarButtons = [[NSMutableArray alloc] init];
[toolBarButtons addObject:buttonGoBack];
[toolBarButtons addObject:fixedSpace];
[toolBarButtons addObject:buttonGoForward];
[toolBarButtons addObject:flexibleSpace];
[toolBarButtons addObject:buttonContainer];
[toolBarButtons addObject:flexibleSpace];
[toolBarButtons addObject:buttonAction];
// Set buttons to tool bar
[self.navigationController.toolbar setItems:toolBarButtons animated:YES];
`
如何启用按钮的按钮的原始颜色=否;是否可以帮助我
答案 0 :(得分:0)
我找到了一个解决方案,很高兴与所有人分享,如果有人遇到同样的问题。
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
通过这种方式,你可以给任何颜色的条形按钮。
答案 1 :(得分:0)
以下链接提供了在UIToolBar中更改UIButton颜色的完整代码 http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem