Question

I have this in my UINavigationController:

(void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.

    self.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationBar.barTintColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor greenColor];
    //self.navigationItem.rightBarButtonItem.tintColor = [UIColor greenColor];
    //self.navigationItem.rightBarButtonItem = nextButton;
}

The first two lines work fine: the text of the navigation bar is white and the background is black. The third (and fourth when I tried), just seem to be ignored.

How do I make the text color of the left and right bar buttons be different colors? I see Apple's apps in ios7 doing this.

Was it helpful?

Solution

I am not sure but if you want to apply the different colors to left and right bar buttons then just try to apply the tintColor independently and remove the line that sets the tintColor to navigationBar. Just try it.

Update :

It looks like Apple don't want us to apply the different color on left and right bar buttons anymore. Behavior from some of the properties of UINavigationBar has changed from iOS 7. I have already given description in my Answer, you can check it.

OTHER TIPS

This should work. I just tested with a minimal app. Make sure the leftBarButtonItem is actually set when you try to tint it.

Different tint colors for left and right UINavigationBar items on iOS 7 iPad 3

I had trouble using the other answers, but this worked great for me.

[self.clearButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                         [UIColor redColor], NSForegroundColorAttributeName,
                                         nil] forState:UIControlStateNormal];

where clearButton is just a reference to my left navigation bar item. Using ios7.

I did this by setting a general color in AppDelegate using:

UINavigationBar.appearance().tintColor = tintColor

Then I would create custom bar button items in individual view controllers and set it as either leftBarButton or rightBarButton.

 let filterStr = NSLocalizedString("FILTER", value: "Filter", comment: "Navigation bar item")
 self.searchButton = UIBarButtonItem.init(title: filterStr, style: .plain, target: self, action: #selector(<someMethod()>)     
 self.searchButton?.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.gray], for: UIControlState.normal)
 self.navigationItem.setLeftBarButton(self.searchButton!, animated: false)

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top