Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add image in UINavigationBar in IPhone app

In my app, i want to add image(logo) in Navigation bar. I am working on XCode 4.2 and iOS 5.

I know UINavigationBar, UIToolBar has been changed in iOS 5. So iOS 4.2 UINavigationBar code won't work in iOS 5.

I want to support display image in UINavigationBar in both 4.2 and 5 version.

I want to be display image in UINavigationBar like as in below screenshot.

Navigation bar image

Please help in this regards and if there is any sample code means its very helpful to me.

Thanks!!!

like image 323
user2136 Avatar asked Jan 11 '12 04:01

user2136


People also ask

What is the navigation bar on Iphone?

The navigation bar is an integral part of the screen that indicates the position of the user within the app and contains the page-level control actions.


1 Answers

One way to do this is to use UINavigationItem.titleView and UINavigationItem.rightBarButtonItem. Like this :

viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]]; UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage2.jpg"]]];     viewController.navigationItem.rightBarButtonItem = item;     

Here I am using UIImageView as custom view, but it can be UIButton with custom image.

like image 65
barley Avatar answered Sep 24 '22 17:09

barley