views:

105

answers:

1

Hi,

I am trying to create a UINavigationController with a background Image...

I have the following code at the top of the class where I implement the UINavigationController.

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed:@"header.jpg"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
}

@end

Then, inside my @implementation of my controller in the "viewDidLoad" function, I have the following...

MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
self.navController = nav;
[nav release];

I know I am close, because everything is working almost perfectly, except the image is 150px in height, and it's being squished down to a smaller size (doing a log of self.frame.size.height is giving me 44.0000) but is pushed down a certain number of pixels from the top...

I know I am close, but if anyone could help me out, it would be muchly appreciated.

Thank you,

--d

A: 

You really need to actually make your image the same size as your navigation bar. Don't try to do this unless you really have art that was made for a UINavigationBar.

This code will work, so long as the dimensions are correct:

- (void)drawRect:(CGRect)rect {
  [img drawInRect:rect];
}

To support different orientations with differently-sized navigation bars, just send -[UIApplication statusBarOrientation] (I've heard from a lot of people that -[UIDevice orientation] doesn't work as expected, but I haven't tried it).

Jonathan Sterling
not the solution i wanted :(, but i appreciate the help!wish it was possible
dewberry