2013-01-02 8 views
1

J'essaie d'implémenter un fond d'image UINavigationBar personnalisé pour iOS 6 mais je n'ai pas de chance. Tout ce qu'il affiche est le normal d'Apple (sans bouton de retour). J'ai essayé le code suivant dans viewDidLoad (un à la fois):Personnalisé UINavigationBar Image

[[UINavigationBar appearance] setBackgroundImage:myImage forBarMetrics:UIBarMetricsDefault]; 

[self.navigationController.navigationBar setBackgroundImage:myImage forBarMetrics:UIBarMetricsDefault]; 

je présente la vue souhaitée par:

optionViewController *choose= [[optionViewController alloc] initWithNibName:@"optionViewController" bundle:nil]; 
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:choose]; 
[self presentViewController: aNavController animated:YES completion:nil]; 

Toute aide serait appréciée. Merci!

+0

Qu'arrive t-il? [self.navigationController.navigationBar setBackgroundImage: [UIImage imageNamed: @ "barImage.png"] pourBarMetrics: UIBarStyleDefault]; Cette commande fonctionne partout dans mon code, à la fois pour iOS5 et iOS6. –

+0

@ LêQuýSang Rien ne se passe ... Il affiche simplement l'UINaviationBar de base typique et non l'image que je veux. Merci –

Répondre

2

vous pouvez définir l'image Barre de navigation sur mesure comme la façon suivante: -

 optionViewController *choose= [[optionViewController alloc] initWithNibName:@"optionViewController" bundle:nil]; 
     UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:choose]; 
     UIImage *image = [UIImage imageNamed:@"imageName"]; 
     [aNavController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 

     [self presentModalViewController:aNavController animated:YES]; //change here to PresentViewcontroller to presentmodelViewcontroller 

ici » est l'image: -

enter image description here

et l'image au-dessus du bouton Back n'est pas celui par défaut , mais ça passe par programme.

+0

Merci pour la réponse, mais si vous regardez ci-dessus, j'ai déjà essayé. D'autres suggestions? Merci –

+0

vous tryong mais vous n'essayez pas avec cette ligne UIImage * image = [UIImage imageNamed: @ "navBarLoc.png"]; juste en train d'essayer ça –

+0

Ahh désolé j'ai supposé que c'était compris ... J'ai cette ligne de code dans mon projet actuel. Merci –

1

Essayez ceci,

if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { 
    //iOS 5 new UINavigationBar custom background 
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg_ForiPhone5_Imagename.png"] forBarMetrics: UIBarMetricsDefault]; 
} else { 
    [self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbg_ForOtherIphone_Imagename.png"]] atIndex:0]; 
} 

et Pour info goto ce link

Questions connexes