aj.esler
aj.esler

Reputation: 931

Redraw UINavigationBar to reflect title text color change

I am trying to use the UINavigationBar title text color as an indication to users as to whether my app has a connection to an external accessory, eg red for disconnected, green for connected.

There is no problem updating the UINavigationBar to have the correct title text color, when the connection status changes, by using the setTitleTextAttributes method then calling [self.navigationBar setNeedsDisplay]. However, the change is not reflected immediately.

I also use [[UINavigationBar appearance] setTitleTextAttributes:... ] so that any new UINavigationBars created in the future will have the correct value. If I navigate to a new view, the navigation bar title is the correct color.

How can I force the UINavigationBar be redrawn immediately with the updated title color?

Upvotes: 3

Views: 2534

Answers (1)

Vincent Tourraine
Vincent Tourraine

Reputation: 801

I think I’ve just run into the same issue. Here’s an easier way to fix this. Assuming this UINavigationBar is the standard UINavigationController’s bar, you just need to re-assign the text being displayed. That’s your controller’s title property. The trick is, you need to change its value in order to make it work.

self.navigationController.navigationBar.titleTextAttributes = @{...}

self.title = nil;
self.title = @"##Actual Title##";

Upvotes: 2

Related Questions