tags:

views:

17

answers:

1

hello all.I want to display an image in navigation bar at the right corner side.Some one please tell me how can i do this.I tried by taking uiimageview at the right corner of navigation bar but i didnt get it.Thanks in advance

A: 

A UINavigationItem (which is what you want to be using here) has got a rightBarButtonItem, which you can set.

Do something like this:

UIBarButtonItem *rightCornerButton = [[UIBarButtonItem alloc] 
                initWithImage:[UIImage imageNamed:@"myAwesomeImage.png"] 
                style:UIBarButtonItemStylePlain target:self 
                action:@selector(functionYouWantToRunWhenBarButtonIsPressed)];
[self.navigationItem setRightBarButtonItem:rightCornerButton];
// If you do it this way, the button will disappear when you call -pushViewController on your navigationController.
[rightCornerButton release];

Or even better (removing the frame around):

UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
[barButton setImage:[UIImage imageNamed:@"reload1.png"] forState:UIControlStateNormal];
UIBarButtonItem *rightCornerButton = [[UIBarButtonItem alloc] initWithCustomView:barButton];
[rightCornerButton setTarget:self];
[rightCornerButton setAction:@selector(functionYouWantToRunWhenBarButtonIsPressed)];
[self.navigationItem setRightBarButtonItem:rightCornerButton];
// If you do it this way, the button will disappear when you call -pushViewController on your navigationController.
[rightCornerButton release];
Emil