I am working on iPhone app. I have added Navigation bar Background image
With interface: -
@interface UINavigationBar (backgroundImageWithTitle)
Using (SDK 3.2.5.) - In one of my Apps I needed navigationBar with custom image both in landscape and portrait.
What I did was:
@implementation UINavigationBar (BackgroundImage)
- (void)drawRect:(CGRect)rect
{
UIImage *image;
if(self.frame.size.width == 320) //for iPhone - portrait will have 320 pix width.
{
image = [UIImage imageNamed: @"portraitNavigationBar.png"];
}
else
{
image = [UIImage imageNamed: @"landscapeNavigationBar.png"];
}
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
Luckily my app supports rotation - so, when rotating - navigation bar automatically redraws itself.
But to manually redraw it - you can also call :
[navigationController.navigationBar setNeedsDisplay];