Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar appearance refresh?

Tags:

In my iPad app I have an application settings view. One of the options lets the user switch interface color scheme. The settings view is loaded by segue to a separate view controller than my "main" app's window.

When they pick a new color I switch the colorSchemeColor variable and do this:

// set the colors and refresh the view [[UINavigationBar appearance] setBarTintColor:colorSchemeColor]; [[UIToolbar appearance] setBarTintColor:colorSchemeColor]; [[UITabBar appearance] setBarTintColor:colorSchemeColor]; 

However, none of the bars change color until I exit my settings view! (When the settings window disappears, the colors for the "main" app change correctly!)

So then I tried to put this code right after to refresh the settings view:

[self.view setNeedsDisplay]; [self.view setNeedsLayout]; 

which didn't help. So I added this as well:

[self.navigationController.view setNeedsDisplay]; [self.navigationController.view setNeedsLayout]; 

This didn't work either.

How can I get my settings view to "redraw" itself when the new color is picked so the change is instantly obvious?

Thanks so much!

like image 272
Kent Avatar asked Feb 08 '14 23:02

Kent


People also ask

How do I change the color of my UINavigationBar?

Open the project's storyboard file. Select the UINavigationBar from your UINavigationController scene. In the Attributes Inspector pane turn on these Appearances: “Standard”, “Compact”, “Scroll Edge”, and “Compact Scroll Edge”. For all four appearances, set the “Background” to “System Red Color”, for example.

Can you change the navigation bar on Iphone?

Change the Bar StyleA user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar. iOS 13.0+ iPadOS 13.0+ Mac Catalyst 13.1+ tvOS 13.0+


2 Answers

The appearance proxy only affects the look of newly initialized views. Setting colors on the appearance proxy will have no effect on navigation bars that are already visible.

You'll need to manually update your current view; for example:

self.navigationController.navigationBar.barTintColor = [UINavigationBar appearance].barTintColor; 
like image 159
Aaron Brager Avatar answered Sep 17 '22 19:09

Aaron Brager


Objective-C:

self.navigationController.navigationBarHidden = YES; self.navigationController.navigationBarHidden = NO; 

Swift:

self.navigationController?.isNavigationBarHidden = true self.navigationController?.isNavigationBarHidden = false 
like image 32
zaolian Avatar answered Sep 20 '22 19:09

zaolian