1

I have a UINavigationController (with a UITableView) inside of a UIPopoverController. When I select a row in the table view I push to a new UIViewController. This view has a navigation bar with a back button. Inside the view there is a button. When I touch this button I want the back button to change color. This needs to work in iOS 6. Is this possible without creating a custom button?

Here is what I have tried:

- (IBAction)changeColor:(id)sender
{
    self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor];

    [[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

    [[UINavigationBar appearance] setTintColor:[UIColor redColor]];

    self.backButton.tintColor = [UIColor redColor]; // Created a UIBarButtonItem outlet and connected it in IB 
}
Chris
  • 1,005
  • 1
  • 13
  • 27

2 Answers2

3

you could use

self.navigationController.navigationBar.tintColor = [UIColor blueColor];

in loadView or viewDidLoad

aguilarpgc
  • 1,181
  • 12
  • 24
  • I need this to happen after the view is loaded – Chris Mar 21 '14 at 21:28
  • override viewWillAppear from UIViewController and add the code – aguilarpgc Mar 21 '14 at 21:32
  • If I put the code in viewWillAppear it will be called when the view loads. I need this to happen when I push a button, after the view is loaded. – Chris Mar 24 '14 at 19:32
  • This solution changes the color of the navigation bar along with the button. I just want the button to change color. It also doesn't work in a popover. – Chris Mar 24 '14 at 19:36
0

You can create an outlet for the button then change the tint color

@property (nonatomic, weak) UIBarButtonItem *item;

and then

-(void)buttonClicked { //or whatever method gets called with the button click
item.tintColor =  [UIColor blueColor]; 
//or 
item.tintColor = [UIColor redColor];
}

in the case of a navigation controller, you would just have to do

    self.navigationItem.backBarButtonItem.tintColor = [UIColor blueColor];
Lucas
  • 713
  • 2
  • 8
  • 19