我已成功使用以下方法将自定义背景添加到导航栏:
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UINavigationBar.png"]];
[myViewController.navigationBar insertSubview:iv atIndex:0];
[iv release];
这工作正常,我可以正常看到标题和按钮。但是,当我向下钻取一层然后返回到根时,按钮被隐藏,但标题仍然可见。导航栏图像似乎覆盖了按钮项目。
我很困惑,因为我将其插入底部,所以我假设当导航项被推送和弹出时,它们显示在导航栏中的其他视图之上。
有任何想法吗?
Thanks,
Mike
根据描述here,我建议在导航栏中添加一个类别。
@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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)