Navigation controller does not work properly

I use the navigation controller in my current application, but I had a problem with the navigation controller with iOS4 and iOS5, so I tried to write code for iOS 4 and 5

if([[UINavigationBar class] respondsToSelector:@selector(appearance)]) //iOS >=5.0
{
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
else
{
    self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"header.png"].CGImage;
}

But the problem is that when I launch my application in iOS 4, my navigation controller looks like this. enter image description here

please suggest me.

0
source share
2 answers
UINavigationController *navControl;

In another part, try to do this.

UINavigationBar *navBar = self.navControl.navigationBar;
   UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
            imgView.image = [UIImage imageNamed:@"header.png"];
            [navBar addSubview:imgView];
            [imgView release];
0
source

Thanks for the long search. I tried this code that helped me.

import "ImageViewController.h"

@implementation UINavigationBar (CustomImage)

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

@end
implement this code in your .m file


@implementation ImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    UIImageView *backGroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    [self.navigationController.navigationBar insertSubview:backGroundView atIndex:0];
    [backGroundView release];
}

@end
+2
source

All Articles