Search code examples
iosuinavigationcontrollertintcolor

Changing tintColor to default (blue) in NavBar


I can change the tintColor for my App (everywhere) in a setting pane. When I change the tintColor, and after that try to return to the default tint color, some buttons in NavBar don't return to blue, how can I handle this?

To verify: - create a new project Master/Detail - In the detail view: add Two buttons, named: "Red Interface" and "Blue interface" - In DetailViewController, add the actions

@IBAction func tapRed(sender: AnyObject) {
    view.window!.tintColor = UIColor.redColor()
}


@IBAction func tapBlue(sender: AnyObject) {
    view.window!.tintColor = nil
}

Now run the application, create a timestamp, go to detail, tap redInterface, then blue interface That's OK in the Detail View, but when you return to Master, the "+" button item is red, not blue.

I can fix the problem by setting a real blue color instead of nil, but that's not a long term solution, if Apple change the default tintColor.

Is this a bug? Is there something I can do to bypass this problem?


Solution

  • A quick workaround would be to fetch the default tint color once on the initial app load and store it somewhere (i.e. in the user defaults)

    From Apple's iOS 7 UI Transition Guide (Specifically under the Using Tint Color section).

    By default, a view’s tint color is nil, which means that the view uses its parent’s tint. It also means that when you ask a view for its tint color, it always returns a color value, even if you haven’t set one.