简体   繁体   English

更改底部工具栏项目的颜色

[英]change BOTTOM toolbar items color

I have a simple toolbar on my screen. 我的屏幕上有一个简单的工具栏。 This toolbar has two items that are buttons. 该工具栏有两个按钮。 The first should be black and the second blue. 第一个应该是黑色,第二个应该是蓝色。 Already changed their color the code and the storyboard but when I run the two still black application. 已经更改了代码和情节提要的颜色,但是当我运行两个仍为黑色的应用程序时。 How can I change the color only the second item? 如何仅更改第二项的颜色?

this is my toolbar; 这是我的工具栏;

在此处输入图片说明

this is my code: 这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.deviceImages.delegate = self;
    self.deviceImages.dataSource = self;
    [self.rigthToolbarItem setTintColor:[UIColor colorWithRed:82/255.0 green:157/255.0  blue:230/255.0  alpha:1.0]];
}

Solution 1: 解决方案1:

Basically, you have to create a UIButton, configure it as you wish, and then initialize the Bar Button Item with the UIButton as a custom view. 基本上,您必须创建一个UIButton,根据需要进行配置,然后使用UIButton作为自定义视图来初始化Bar Button Item。 like: 喜欢:

UIButton *button = [UIButton buttonWithType:....];
...(customize your button)...

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];

or 要么

Solution 2: 解决方案2:

To change the color of title: iOS7: 更改标题的颜色:iOS7:

UIBarButtonItem *button = 
 [[UIBarButtonItem alloc] initWithTitle:@"Title" 
                                  style:UIBarButtonItemStyleBordered 
                                 target:nil 
                                 action:nil];
[button setTitleTextAttributes:
          [NSDictionary dictionaryWithObjectsAndKeys: 
               [UIColor redColor], NSForegroundColorAttributeName,nil] 
                                            forState:UIControlStateNormal];

and prior iOS7:

UIBarButtonItem *button = 
  [[UIBarButtonItem alloc] initWithTitle:@"Title" 
                                   style:UIBarButtonItemStyleBordered 
                                  target:nil 
                                  action:nil];
[button setTitleTextAttributes:
          [NSDictionary dictionaryWithObjectsAndKeys: 
               [UIColor redColor], UITextAttributeTextColor,nil] 
                                    forState:UIControlStateNormal];

Hope it would help to figure out the solution for your question. 希望能为您的问题找到解决方案。

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

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