How to add custom navigation bar (navigation bar with image)

Posted: Thursday, April 14, 2011 | Posted by Dipak Mishra | Labels: ,
A lot of time I came across a common problem of showing background image in navigation bar of iPhone application. For very first time, I used a very uncommon solution of inserting an image view in navigation bar. But then came other problem like showing title, left bar button and right bar button were getting hidden.

After a bit research I found a very easy solution of this problem. As a solution, we need to write few lines in Application's app delegate file and the navigation bar for that particular gets customized accordingly. Below is the code:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"iphone_bar.jpg"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

If this piece of code solves you problem, do leave a comment below.

Enjoy!

Share

0 comments:

Post a Comment