将导航栏的背景图片还原为默认值 [英] Revert navigation bar's background image to default
本文介绍了将导航栏的背景图片还原为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先,我将导航栏的背景设置为半透明。
At first, I set navigation bar's background to translucent.
barImage=[[self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] copy];//barImage is a UIImage point
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
它工作得很好。
现在我需要将导航栏的背景图片恢复为默认值。
It works well. Now I need to revert navigation bar's background image to default.
- (void)dealloc
{
[self.navigationController.navigationBar setBackgroundImage:barImage
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
}
这不起作用。我应该怎么办?
This doesn't work. What should I do?
推荐答案
不知道你是否仍然坚持这一点,但这里是反转效果的代码。我借了一个导航控制器,并将一切复制到原来的导航控制器。
Not sure if you're still stuck on this, but here's the code to reverse the effect. I borrowed a navigation controller, and copied everything over to the original navigation controller.
UINavigationController *tempNavigationController = [[UINavigationController alloc]initWithRootViewController:[[UIViewController alloc]init]];
[self.navigationController.navigationBar setBackgroundImage:[tempNavigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [tempNavigationController.navigationBar shadowImage];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = tempNavigationController.view.backgroundColor;
tempNavigationController = nil;
这篇关于将导航栏的背景图片还原为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文