0

I'm using this:

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationController class], nil]
 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                         color ,NSForegroundColorAttributeName,
                         FONT(FONT_REGULAR, 15.0f), NSFontAttributeName,
                         nil] forState:UIControlStateNormal];

To set a color for button in UINavigationController on viewWillAppear: methods. My application has 5 main views each with UINavigationController grouped under UITabBar.

Problem is that when I switch between UITabBar views, it goes crazy and it always apply the last initialized view color to all other views. I tripple check code is running when I change with proper parameters it just has no effect on existing buttons.

Is there any other way to set color separately for different UINavigationControllers ?

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71

1 Answers1

0

Don't use appearanceWhenContainedIn: method, it changes appearance of all the instances of a class. In Your situation this class is the UIBarButtonItem. And you are doing it at viewWillAppear: method again and again which causes to change the colors of all your UIBarButtonItem objects.

This question gives answer to your problem:

iOS 6 appearance when contained in multiple classes

EDIT:

As a solution you can use tintColor property for exact UIBarButtonItem object.

myBarButtonItem.tintColor = [UIColor blueColor];
Community
  • 1
  • 1
Shamsiddin Saidov
  • 2,281
  • 4
  • 23
  • 35