简体   繁体   English

清除iPhone导航栏图像

[英]Clear iPhone Navigation Bar Image

I am currently using this code in my App Delegate to set a custom background image for the Navigation bar: 我目前在App Delegate中使用此代码为导航栏设置自定义背景图像:

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

It works great, and for all the views in my App I set the Navigation bar title to show no text (so it won't cover up the background image). 它工作得很好,对于我的应用程序中的所有视图,我将导航栏标题设置为不显示文本(因此它不会覆盖背景图像)。

One of the views presents a modal view controller (an EKEventEditViewController to be exact), and the title in the Navigation bar says "Add Event", which shows up on top of my custom image. 其中一个视图提供了一个模态视图控制器(确切地说是一个EKEventEditViewController),导航栏中的标题显示“添加事件”,它显示在我的自定义图像之上。

I have tried several ways to change the title (to no avail), but would rather prevent the custom Navigation bar background image from showing up only in this modal view. 我已经尝试了几种方法来更改标题(无济于事),但宁愿防止自定义导航栏背景图像仅在此模态视图中显示。

Does anyone know of a way to do this while still using the stated method for setting the Navigation bar background image? 有没有人知道如何使用所述方法设置导航栏背景图像?

please, never ever do this... 拜托,永远不要这样做......

You are replacing the drawRect: method in UINavigationBar, very brittle and likely to cause you (and your users) headaches. 您正在替换UINavigationBar中的drawRect:方法,非常脆弱,可能会导致您(和您的用户)头痛。

Your background will always show up in all instances of UINavigationBar because you have replaced the implementation of drawRect: 您的背景将始终显示在UINavigationBar的所有实例中,因为您已替换了drawRect的实现:

There is no way to replace the title of the EKEventEditViewController. 无法替换EKEventEditViewController的标题。 Of course there is always a way, but its even worse than replacing the implementation of drawRect: 当然总有一种方法,但它比替换drawRect的实现更糟糕:

Instead, please make a subclass of UINavigationBar and use that in the places you require a custom nav bar. 相反,请创建UINavigationBar的子类,并在需要自定义导航栏的位置使用它。

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

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