【问题标题】:change BOTTOM toolbar items color更改 BOTTOM 工具栏项目的颜色
【发布时间】:2016-11-03 13:02:31
【问题描述】:

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

这是我的工具栏;

这是我的代码:

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

【问题讨论】:

    标签: objective-c toolbar ios8.3


    【解决方案1】:

    解决方案 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];
    

    希望它能帮助您找出问题的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      相关资源
      最近更新 更多