nico
nico

Reputation: 1067

navigation bar background image

how can i set an image into the background of the navigation-bar, so that is also in the background of the back-button ? now i have an image with a with of 320 pixels, but it shrinks that image so, that the left back-button is the standard-button and on the right side there are 5 pixels in the standard-blue. i want that this image is over the fuel width and maybe i will do a darker back-button later.

Upvotes: 3

Views: 2443

Answers (1)

nico
nico

Reputation: 1067

@implementation UINavigationBar (UINavigationBarCategory)

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


@end

I have found this snippet. so the image is on every navigationbar as background and i can set the old image as the view in the middle. maybe I dont understand why that works, but it works. sorry for the dumb question.

EDIT: For iOS 5

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

Upvotes: 3

Related Questions