0
votes

I'm trying to change the Navbar tint at runtime, and I'm able to change the navigation bar tint, but then the left and right buttons (which were system blue on iOS 7) changed, so I'm trying to force them back to the system blue color. this is the code I am using, called from viewDidLoad: I've tried both NSForegroundColorAttributeName and UITextAttributeTextColor, but I keep getting white or black text, depending on the color of the navigation bar.

How can I get the buttons to show blue text?

    NSDictionary *btnAttr =   [NSDictionary dictionaryWithObjectsAndKeys:
                               [UIFont boldSystemFontOfSize:14], UITextAttributeFont,
                               [UIColor blueColor], NSForegroundColorAttributeName,
                               nil];
    for(UIView *v in [theView.view allSubViews])
    {
        if([v isKindOfClass:[UINavigationItem class]])
        {
            UINavigationItem *btn = (UINavigationItem *)v;
            [btn.leftBarButtonItem setTitleTextAttributes:btnAttr forState:UIControlStateNormal];
            [btn.rightBarButtonItem setTitleTextAttributes:btnAttr forState:UIControlStateNormal];
        }
    }
1

1 Answers

4
votes

In iOS7 you if you need to change the navigationBar buttons color, you need to set tintColor:

navigationController.navigationBar.tintColor = [UIColor blueColor];

For better understanding check the image below:

enter code here