1

I am trying to change the font color on tab bar items. I'm using code from this post:

change tabbar text color,iPhone

My code is as follows:

if ([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes:)]) {
    NSLog(@"yes");
    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                             darkGreen, UITextAttributeTextColor,
                                             nil] forState:UIControlStateNormal];
}
else {
    NSLog(@"no");
}

respondsToSelector always returns no, and I'm stuck as to how to fix it. This code block is in viewDidLoad, and the class is a subclass of UITabBarController.

Any ideas?

Community
  • 1
  • 1
AUSTOOO
  • 41
  • 1
  • 9

1 Answers1

0

This method setTitleTextAttributes: doesn't exists at all, the correct signature of that method is setTitleTextAttributes: forState:

if ([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes: forState:)]) {
    NSLog(@"yes");
    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                             darkGreen, UITextAttributeTextColor,
                                             nil] forState:UIControlStateNormal];
}
else {
    NSLog(@"no");
}
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
  • Ahhhh how silly of me. I cannot believed I overlooked that! Thank you. I changed it and it returns yes, but doesn't update the text color. Would you know where to go from here? – AUSTOOO Feb 02 '13 at 04:49
  • try replacing `self.tabBarItem` with `[UITabBarItem appearance]` – Inder Kumar Rathore Feb 02 '13 at 04:55
  • Thanks for the quick response. I replaced it and had no luck. Would it be something in storyboard? – AUSTOOO Feb 02 '13 at 05:00
  • I have written this code in the viewDidLoad method of my custom class that subclasses UITabBarController. i just tried to put this in my appDelegate with no luck. In my appDelegate (under applicationDidFinishLaunching) I created one of my custom class objects and used the same code, substituting 'self' with the object. Am I going about this the right way? – AUSTOOO Feb 02 '13 at 05:13
  • I just created a tab bar application using storyboard and put the code `[[UITabBarItem appearance] setTitleTextAttri.....];` in `didFinishLaunching` and it worked. I suggest you to try that and see the effect. Create a new dummy project to test it – Inder Kumar Rathore Feb 02 '13 at 05:17
  • `[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor yellowColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];` – Inder Kumar Rathore Feb 02 '13 at 05:30