1

我有一个应用程序,我在其中创建了一个工具栏来浏览 web 视图。一切正常,除了按钮的颜色。当我不启用按钮时,它显示为与 tint 颜色相同的颜色工具栏。当我启用它时,它显示为白色。但我需要按原样显示按钮。这就是我的做法,`

[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];

`

我怎样才能获得按钮启用按钮的原始颜色=否;有人可以帮我吗

4

2 回答 2

0

我已经制定了一个解决方案,如果有人遇到同样的问题,很高兴与大家分享。

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

通过这种方式,您可以为条形按钮赋予任何颜色。

于 2013-07-15T11:43:30.863 回答
0

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

于 2013-07-15T11:55:41.640 回答