0

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.

1
  • After looking at the ios 7 apps, I guess this cannot be done. Commented Oct 1, 2013 at 7:59

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

are you running in ios 7, cause the above text for the bar buttons is blue when i run the above code
@chris : No. I am just giving you the hint.
yeah okay, seems ios 7 doesn't like this, the layout transition guide doesn't show this as a possibility - developer.apple.com/library/ios/documentation/UserExperience/…
@chris: Yes, I know that. But I was thinking if they removed that part then they should also remove the tintColor property for left and right Bar Buttons.
1

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

7 Comments

is this ios 7 you are running in?
Of course. Oh, I just noticed I only tested on the simulator. I've noticed that especially with regard to bars and tint in iOS 7, behavior and bugs may differ between simulator and device (and even among devices). Be right back.
I've tried it on the device; see attached screenshot. Please forgive the color choice, this was a test app intended to make coloring differences very clear.
Note: If this doesn't work for you, it may be a sequence issue. Maybe your change is being overwritten by something. In my test project (originally created to test something else), I set rootVC.navigationItem.rightBarButtonItem.tintColor externally, after its view has been loaded (but before it is displayed). In any case, there is a way to make it work, and if it doesn't work for you right away, try setting the tintColor later (like in loadView).
Is it my eyes or does your picture have blue text on both the left and right sides of the lime green nav bar?
|
1

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.

1 Comment

UITextAttributeTextColor is deprecated on iOS7, use NSForegroundColorAttributeName instead
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.