4

I want to add an image in the navigation bar. It should be throughout my app. It should be added to all navigation controllers.

Any help will be appreciated.

numaroth
  • 1,295
  • 4
  • 25
  • 36
Dhruv
  • 43
  • 4
  • check this link also http://stackoverflow.com/questions/1692487/how-to-add-background-image-on-iphone-navigation-bar?rq=1 – dead_soldier May 24 '13 at 06:57

5 Answers5

4

Try this ,

UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"image.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Pratik B
  • 1,599
  • 1
  • 15
  • 32
3

you can add image with bellow code..

UIImage *image = [UIImage imageNamed: @"yourImageName.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage: image];
self.navigationItem.titleView = imgView;
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
2
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
    {
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]] forBarMetrics:UIBarMetricsDefault];
        [[UINavigationBar appearance] setTitleTextAttributes:
         [NSDictionary dictionaryWithObjectsAndKeys:
          [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
          UITextAttributeTextColor,
          [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
          UITextAttributeTextShadowColor,
          [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
          UITextAttributeTextShadowOffset,
          [UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0],
          UITextAttributeFont,
          nil]];
    }

put this in your Appdelegate.m

Manu
  • 4,730
  • 2
  • 20
  • 45
2

u use this code:

 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault];
kirti Chavda
  • 3,029
  • 2
  • 17
  • 29
0

i am an ideal , because i have got issue like this ,so you can try my way,ok!!

the first,you create an navigationcontroller and then show it on window

UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:YourView];

next step : you create an object Uiimageview with image property with your image which you want to add navigationbar and frame ptoperty is posittion which you want

UIImageView *imgView=[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImagename"]; imgView.Frame=CGrectmake();

last step: you add object imgView in navigationbar as subview

[nav.navigationBar addSubview:imgView];

Done!!!!!!!!!!