Unable to set full image in navigation bar.

I canโ€™t set the full image in the navigation bar (or the navigation controller at the top of the application). there will be little space on the left side. And when I put the info button, it is not in the image. How to fix it?

here is my code pls look

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]]; img.frame = CGRectMake(0, 0, 320, 44); self.navigationItem.titleView =img; [img release]; UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain]; infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0); infoDarkButtonType.backgroundColor = [UIColor clearColor]; [infoDarkButtonType addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType]; self.navigationItem.leftBarButtonItem = infoButton; [infoDarkButtonType release]; [infoButton release]; 

thank you very much.

Me.

+4
source share
2 answers

If you want the image displayed on the navigation bar, you can try this

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

Use this line of code and add an image to the NavigationController ...

 UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]]; img.frame = CGRectMake(0, 0, 320, 44); [self.navigationController.navigationItem addSubView:img]; [img release]; 

Now you set the image in navigation.

0
source

All Articles