0

In my iPhone app i have to change the UINavigationBar image on Button click.

so following is the function am calling on buttoclick

-(void)btnBlueDelegate{


    // Create resizable images
    UIImage *gradientImage44 = [[UIImage imageNamed:@"header_Blue.png"]
                                resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    UIImage *gradientImage32 = [[UIImage imageNamed:@"header_Blue.png"]
                                resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    // Set the background image for *all* UINavigationBars
    [[UINavigationBar appearance] setBackgroundImage:gradientImage44
                                       forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:gradientImage32
                                       forBarMetrics:UIBarMetricsLandscapePhone];

    //[[UINavigationBar appearance]setBackgroundColor:[UIColor blueColor]];

    [self.view  setNeedsDisplay];

}

Now my problem is that the navigation bar changes take effect when i go to another view.but it does not change immediately after the button click for same view controller.

I know the reason that my navigation bar drawn already so it cant change on button click..so can anyone please tell me how can i change my current view's Navigation bar even after a button click..

May be i have to reload the whole view.. but don't know how can i do it.

Thanks in Advance.

BhavikKama
  • 8,566
  • 12
  • 94
  • 164
  • http://stackoverflow.com/questions/13488710/how-to-set-a-picture-programmatically-in-a-navbar/13488781#13488781 – Rajneesh071 Sep 16 '13 at 12:45

1 Answers1

2

Call this method on your UIButton Action method:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"header_Blue.png"] 
               forBarMetrics:UIBarMetricsDefault];
Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
  • i have to change it on all view controller so i need to write both the code [self.navigationController.navigationBar setBackgroundImage: and the one i am using? – BhavikKama Sep 16 '13 at 12:31