I am working on an app that is driven by a main UINavigationController. The first view is a table view where each element pushes in a different section of the app. I want each section to have a distinct color scheme, different than that of the main (first) view, therefore I would like the UINavigationBar to reflect this color change.
I can programmatically change the underlying UINavigationBar of the UINavigationController at one of several points (from root view when about to push the new view, from viewDidLoad, viewWillAppear or viewDidAppear of the new view), but all of these result in the bar changing color instantly. What I am left with is the bar flashing to the new color either before or after the animation of the push occurs.
What I am wondering is if there is a way to make this look cleaner. Ideally, I’d like the new bar color to push in along with the new view, as if the view I am pushing had it’s own UINavigationBar manually added to the top, separate from that of the UINavigationController’s bar.
you can achieve what you are looking for by extending the
UINavigationBarto your custom class and then overriding the-(void)drawRect:(CGRect)rectmethod and implementing the color update in there.Don’t forget to call
setNeedsDisplay.Best of luck.