IPhone iOS how to redraw UINavigationBar on demand?

Up vote 0 down vote favorite share g+ share fb share tw.

I have code that changes the color of navigation bar using appearance attribute. I would like the change to the navbar color to be visible immediately. However, I cannot find a proper call to make to redraw the navbar.

Currently it's color changes when I push a modal navigation controller, thus covering the navbar. This does not work: AppDelegate* appDelegate = ((AppDelegate*)UIApplication sharedApplication delegate); appDelegate. Window setNeedsDisplay; I also tried asking various instances of navigation controller to redraw their views, which did not work.

What's the correct way to ask the UINavigationBar to redraw itself on demand? Thank you! UPDATE: Here's the code that works!

- (UIColor *) colorOfPoint:(CGPoint)point { unsigned char pixel4 = {0}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast); CGContextTranslateCTM(context, -point. X, -point. Y); self.view.

Layer renderInContext:context; CGContextRelease(context); CGColorSpaceRelease(colorSpace); NSLog(@"pixel: %d %d %d %d", pixel0, pixel1, pixel2, pixel3); float red = pixel0/255.0; float green = pixel1/255.0; float blue = pixel2/255.0; float alpha = pixel3/255.0; UIColor *color = UIColor colorWithRed:red green:green blue:blue alpha:alpha; NSUserDefaults standardUserDefaults setFloat:red forKey:@"navBarRed"; NSUserDefaults standardUserDefaults setFloat:green forKey:@"navBarGreen"; NSUserDefaults standardUserDefaults setFloat:blue forKey:@"navBarBlue"; NSUserDefaults standardUserDefaults setFloat:alpha forKey:@"navBarAlpha"; return color; } - (IBAction)handleTapFrom:(id)sender { if(sender isKindOfClass:UITapGestureRecognizer class) { CGPoint location = tapGestureRecognizer locationInView:self. View; //remember color preferences UIColor* navbarColor = self colorOfPoint:location; selectColorView. Center = location; //UPDATE THE NAVBAR COLOR CODE HERE //this does not update immediately float navBarRed = NSUserDefaults standardUserDefaults floatForKey:@"navBarRed"; float navBarGreen = NSUserDefaults standardUserDefaults floatForKey:@"navBarGreen"; float navBarBlue = NSUserDefaults standardUserDefaults floatForKey:@"navBarBlue"; float navBarAlpha = NSUserDefaults standardUserDefaults floatForKey:@"navBarAlpha"; UIColor* navBarColor = UIColor colorWithRed:navBarRed green:navBarGreen blue:navBarBlue alpha:navBarAlpha; //set the color of all newly created navbars UINavigationBar appearance setTintColor:navBarColor; UINavigationBar appearance setBarStyle:UIBarStyleBlackTranslucent; UINavigationBar appearance setAlpha:0.7; //update the toolbar appearance UIToolbar appearance setTintColor:navBarColor; //set the color of the current navbar, displaying immediate change self.

NavigationController.navigationBar. TintColor = navbarColor; } } iphone ios uinavigationcontroller uinavigationbar link|improve this question edited Mar 1 at 16:32 asked Feb 28 at 15:28Alex Stone1,630422 83% accept rate.

Have you tried myNavigationController. NavigationBar setNeedsDisplay; – Art Gillespie Feb 28 at 15:31 When you want to redraw your navigation bar? – R.

A Feb 28 at 15:31 Is it even the right navigation controller or is the pushed controller’s nav bar being set? Can you post your code where you set the navigation bar’s color? —that would be more relevant.

– JoePasq Feb 28 at 15:44 My root navigation controller comes from a storyboard, the code you suggested does not work for that. – Alex Stone Feb 280 at 16:26.

That should work: self. NavigationController.navigationBar. TintColor = UIColor redColor.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions