Adding image to Navigation bar in xcode?

iphone, uinavigationbar, xcode

Solution

@implementation UINavigationBar (CustomImage) -(void)drawRect:(CGRect)rect { 

     CGRect currentRect = CGRectMake(0,0,100,45); 
     UIImage *image = [UIImage imageNamed:@"ic_launcher.png"]; 
     [image drawInRect:currentRect]; 
} 
@end 

UPDATE

just add this code in your `viewDidLoad:` method..

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

and also if you want to direct set image in background of NavigationBar then use bellow line...

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"i_launcher.png"] forBarMetrics:UIBarMetricsDefault];

also see this Link how-to-add-a-customized-image-button-to-uinavigationbar-in-iphone-sdk

i hope this help you...

Problem

I have added Navigation bar and Navigation Item in xib. Now I need to add image to the left of Navigation bar, but its not getting added. This is the code I'm working on: ``` - (void)viewDidLoad { UIImage *image = [UIImage imageNamed: @"i_launcher.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; self.navigationItem.titleView = imageView; [imageView release]; } ``` I can't understand why the image is not getting added. How can I add it?

Original source

Related problems