更改BOTTOM工具栏项目的颜色

时间:2015-08-03 13:45:16

标签: objective-c toolbar ios8.3

我的屏幕上有一个简单的工具栏。此工具栏有两个按钮项。第一个应该是黑色而第二个应该是蓝色。已经改变了代码和故事板的颜色,但是当我运行两个仍然是黑色的应用程序时。如何仅更改第二项的颜色?

这是我的工具栏;

enter image description here

这是我的代码:

- (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]];
}

1 个答案:

答案 0 :(得分:0)

解决方案1:

基本上,您必须创建一个UIButton,根据需要进行配置,然后使用UIButton作为自定义视图初始化Bar Button Item。 像:

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

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

解决方案2:

更改标题的颜色: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];

希望有助于找出问题的解决方案。

相关问题