1

I have these two buttons in a toolBar and wants to change the color of UIBarButtons how can i do such a thing? i've tried setTitleTextAttributes, but it does not seem like it has a object with that? How can i do this

UIBarButtonItem *sysDoneButton = [self createButtonWithType:UIBarButtonSystemItemDone target:self
                                                         action:@selector(actionPickerDone:)];

UIBarButtonItem *sysCancelButton = [self createButtonWithType:UIBarButtonSystemItemCancel target:self
                                                           action:@selector(actionPickerCancel:)];
David Berry
  • 40,941
  • 12
  • 84
  • 95
Peter Pik
  • 11,023
  • 19
  • 84
  • 142
  • The syntax in your example is Objective-C, and the example shows nothing about a color. But creating a UIBarButtonItem and linking it to a selector. I am not sure if you are asking how to convert the above code to Swift. Could you please clarify? – Acludia Nov 13 '14 at 19:45
  • Sry trying to do it in objetive-c – Peter Pik Nov 13 '14 at 20:24

2 Answers2

4

A UIBarButtonItem's color is its tintColor. (Or it can use the tintColor inherited from the toolbar you put it into.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • tintColor did not work? could that be because i already applied a color for all in appDelegate? – Peter Pik Nov 13 '14 at 20:06
  • tintColor did not work. i Also tried [navigation.navigationItem.leftBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:]]; But no luck at all. is it because i applied for all navigation item color in appDelegate ? – Tanvir Nayem Sep 28 '17 at 03:15
  • @OceanBlue don't leech in the comments; ask a new _question_ – matt Sep 28 '17 at 04:02
0

It seems UIBarButtonItems won't change it's tint color once they are added to the navigation bar.

What I did was to create a new one instead with new attributes.

let rightBarButtonItem = UIBarButtonItem(title: "Title", style: .plain, target: self, action: #selector(someAction))
rightBarButtonItem.tintColor = UIColor.white
navigationItem.rightBarButtonItem = rightBarButtonItem
odm
  • 888
  • 1
  • 14
  • 22