0

I have a navigation view controller with root view controller where I set the look of the navigation bar. It looks like this:

UIImage *navBarImage = [UIImage imageNamed:@"GreyUp.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage
                                       forBarMetrics:UIBarMetricsDefault];

This thing though, changes the navBar appearance for all the following view controllers, which I would not like. I would like one navBar for root view and another one - for a different view. How can this be achieved?

Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120
  • 1
    follow my answer http://stackoverflow.com/questions/13565962/how-to-programmetically-add-navigation-bar-and-back-button-on-it/13619760#13619760 – Rajneesh071 Jan 16 '13 at 11:58
  • http://stackoverflow.com/questions/13488710/how-to-set-a-picture-programmatically-in-a-navbar/13488781#13488781 – Rajneesh071 Jan 16 '13 at 12:06

5 Answers5

2

Appearance means It is applying into all your app navBar so you can add this in to your all view controller

self.navigationController.navigationBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"GreyUp.png"]];
Bhavesh Lathigara
  • 1,355
  • 1
  • 15
  • 25
1

Yes it can be achived use this in view will appear

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBar.png"] forBarMetrics:UIBarMetricsDefault];

// for cutom back button

UIButton*    btnBack= [Utils createButtonWithTarget:self selector:@selector(btnBackClicked) frame:CGRectMake(0,5, 100, 40) bgimageName:@"tab_back.png" tag:0];//My method use yours
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:btnBack];
      //use btnBack ref to change font title title color etc

My Utils class code to create button

+ (UIButton *)createButtonWithTarget:(id)target
                            selector:(SEL)selector
                               frame:(CGRect)frame
                         bgimageName:(NSString *)imageName
                                 tag:(NSInteger)aTag{
    UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    button.frame = frame;
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];   
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    // in case the parent view draws with a custom color or gradient, use a transparent color
    button.backgroundColor = [UIColor clearColor];
    button.showsTouchWhenHighlighted = YES;
    button.tag = aTag;
    return [button autorelease];
}
amar
  • 4,285
  • 8
  • 40
  • 52
1

You can set your navigationBar for different view

 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"login.png"] forBarMetrics:UIBarMetricsDefault];  

get button on navigation bar you can follow my answer

How to set a picture programmatically in a NavBar?

Community
  • 1
  • 1
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
1

In the viewWillAppear of rootViewController, customize your navigationBar.

In the viewWillDisAppear of rootViewController, do the changes which you want to display for rest of the navigation hierarchy..

Apurv
  • 17,116
  • 8
  • 51
  • 67
0

set a background color for your navigation bar or use Appearance method. where ever you want to change the image of navigation bar in viewWillAppear

Durga Vundavalli
  • 1,790
  • 22
  • 26