Wednesday, 18 April 2012

Adding an image in Navigation bar in iOS5

Add the code just above the @implementation of rootview controller

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:@"Header.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

@implementation RootViewController


//Paste the following code wherever you rerequire.

- (void)viewDidLoad {
    [super viewDidLoad];
      
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        UIImage *image = [UIImage imageNamed:@"Header.png"];
        [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    }
}

No comments:

Post a Comment