简体   繁体   English

如何在工具栏中显示按钮的原始颜色

[英]how to show the orginal color of the button in a toolbar

I had an application in which i am creating a toolbar to navigate through the web view .everything is working fine,except for the color of the button.when i am not enabling the button it is showing as the same color as the tint color of the toolbar.and when i enable it it is showing as white.but i need to present the button as it is.here is how i am doing it ,` 我有一个应用程序,其中我正在创建一个工具栏以浏览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];

` `

how can i get the orginal color of the button for button enabled=NO;Can anybody help me 我如何获取启用按钮的按钮的原色=否;有人可以帮助我吗

I had made out a solution ,happy to share with all if anybody facing the same problem. 我已经提出了一个解决方案,很高兴与所有面临相同问题的人分享。

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

In this way you can give any color the barbuttons. 这样,您可以给任何颜色的按钮。

以下链接提供了完整的代码,用于更改UIToolBar中的UIButton的颜色http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM