¿Quiero cambiar la imagen de fondo de la barra de navegación cuando me muevo a la otra vista en el iPhone?

I am developing an app were I have to place images on the navigation-bar, whenever the user moves to the other view, different images have to appear in navigation bar. Could someone provide me with some guidance how to do this?

preguntado el 31 de enero de 12 a las 08:01

how did you implement this in your project? any code? -

2 Respuestas

This might be more of a generic approach.

Create a Category for UINavigationBar and in the".h" file

@interface  UINavigationBar (UINavigationBarCategory)



and in the ".m" file

@implementation UINavigationBar (UINavigationBarCategory)

-(void)setBackgroundImage: (UIImage*)image

    if (image)

        UIImageView *img = [[UIImageView alloc]initWithImage: image];
        aTabBarBackground.frame = CGRectMake(60,0, 200, 45);//Frame depends upon you 
        [self addSubview:img];
        [img release];


And then from every Controller's 'viewwillAppear' you can do something like this:

 [self.navigationController.navigationBar setBackgroundImage: @"abc.png"];

Respondido el 31 de enero de 12 a las 15:01

try this code ...

UINavigationBar *navigationBar=[[self navigationController]navigationBar];
UIImage *backgroundImg =[UIImage imageNamed:@"example.png"];
[navigationBar setBackgroundImage:backgroundImg forBarMetrics:UIBarMetricsDefault];

agregue este código en ver and give the image name to be displayed instead of example.png

Respondido el 31 de enero de 12 a las 14:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.