Ich habe dieses Code-Schnipsel in ViewDidLoad eines UIViewController verwendet. Ich habe keine Fehler. Bilder existieren. Ich bekomme den Hintergrund, aber nicht das Bild. Das Bild ist eine Art Logo.Wie lege ich ein Bild in die Mitte der Navigationsleiste eines UIViewControllers?
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
/* Background of navigationBar. */
UIImage * navigationBarImage = [UIImage imageNamed:@"01_navbar_portrait.png"];
[self.navigationController.navigationBar setBackgroundImage:navigationBarImage forBarMetrics:UIBarMetricsDefault];
/* Image in navigationBar */
UIImage * logoInNavigationBar = [UIImage imageNamed:@"01_logo.png"];
UIImageView * logoView = [[UIImageView alloc] init];
[logoView setImage:logoInNavigationBar];
self.navigationController.navigationItem.titleView = logoView;
}
Wenn Sie das Bild (Logo) in der Mitte der Navigationsleiste platzieren, dann über Ihren Titel? – Hari1251
Sie müssen das Navigationselement des View-Controllers, das auf den Navigations-Stack geschoben wird, und nicht das Navigationselement des Navigations-Controllers selbst einstellen. Siehe meine Antwort. – jhabbott