UINavigationBar问题的自定义背景 [英] Custom background for UINavigationBar problems

查看:109
本文介绍了UINavigationBar问题的自定义背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使用以下方法在我的导航栏中添加自定义背景:

I've managed to add a custom background to my navigation bar by using:

UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UINavigationBar.png"]];
[myViewController.navigationBar insertSubview:iv atIndex:0];
[iv release];

这很好用,我可以看到标题和按钮没问题。但是,当我向下钻取一个级别然后返回到根时,按钮被隐藏,但标题仍然可见。导航栏图像似乎覆盖了按钮项目。

This works fine and I can see the title and buttons okay. However, when I drill down one level and then go back to the root, the buttons are hidden, but the title is still visible. It appears the navigation bar image is covering the button items.

我很困惑,因为我将它插入底部所以我会假设导航项目被推送并弹出它们显示在导航栏中的其他视图上方。

I'm confused as I'm inserting it at the bottom so I would assume when the navigation items are pushed and popped that they are displayed above other views in the navigation bar.

任何想法?

谢谢,

Mike

推荐答案

按照这里,我建议在导航栏中添加一个类别。

Following the description from here, I suggest adding a category to the nav bar.

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect {
    // Drawing code 
    UIImage *img = [UIImage imageNamed: @"navbar_background.png"];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawImage(context, CGRectMake(0, 0, 320, self.frame.size.height), img.CGImage);

}
@end

这篇关于UINavigationBar问题的自定义背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆