清晰的 iPhone 导航栏图像
我目前正在我的应用程序委托中使用此代码为导航栏设置自定义背景图像:
@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
它效果很好,对于我的应用程序中的所有视图,我将导航栏标题设置为不显示文本(因此它不会覆盖上背景图像)。
其中一个视图呈现了一个模态视图控制器(准确地说是一个 EKEventEditViewController),导航栏中的标题显示“添加事件”,它显示在我的自定义图像的顶部。
我尝试了多种方法来更改标题(无济于事),但宁愿阻止自定义导航栏背景图像仅显示在该模式视图中。
有谁知道如何在仍然使用上述方法设置导航栏背景图像的同时执行此操作?
I am currently using this code in my App Delegate to set a custom background image for the Navigation bar:
@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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请永远不要这样做...
您正在替换 UINavigationBar 中的 drawRect: 方法,该方法非常脆弱,并且可能会给您(和您的用户)带来头痛。
您的背景将始终显示在 UINavigationBar 的所有实例中,因为您已经替换了 drawRect 的实现:
无法替换 EKEventEditViewController 的标题。当然总有办法,但它比替换drawRect的实现更糟糕:
相反,请创建UINavigationBar的子类并在需要自定义导航栏的地方使用它。
please, never ever do this...
You are replacing the drawRect: method in UINavigationBar, very brittle and likely to cause you (and your users) headaches.
Your background will always show up in all instances of UINavigationBar because you have replaced the implementation of drawRect:
There is no way to replace the title of the EKEventEditViewController. Of course there is always a way, but its even worse than replacing the implementation of drawRect:
Instead, please make a subclass of UINavigationBar and use that in the places you require a custom nav bar.