简体   繁体   English

导航栏背景图像

[英]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. 现在我有一个320像素的图像,但它会缩小该图像,左后按钮是标准按钮,右侧是标准蓝色的5像素。 i want that this image is over the fuel width and maybe i will do a darker back-button later. 我希望这个图像超过燃料宽度,也许我稍后会做一个更暗的后退按钮。

@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 编辑:适用于iOS 5

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM