繁体   English   中英

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

[英]change BOTTOM toolbar items color

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

这是我的工具栏;

在此处输入图片说明

这是我的代码:

- (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:

基本上,您必须创建一个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];

希望能为您的问题找到解决方案。

暂无
暂无

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

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