ale*_*ran 5 uinavigationbar uiimage uinavigationcontroller ios
我的应用程序使用导航控制器,主页导航栏中有图像.背景图像是通过推杆完成的
[navigationController.navigationBar setBackgroundImage:navImage forBarMetrics:UIBarMetricsDefault];
[_window addSubview:navigationController.view];
Run Code Online (Sandbox Code Playgroud)
在应用程序委托中.导航栏显示此图像正常.
每个其他视图在导航栏中都没有图像.因此,我需要在按下任何其他视图控制器时删除此背景图像.有谁知道如何做到这一点?
在线有很多关于添加或更改导航栏图像的答案,但这个问题有点不同.先感谢您.
要在iOS 5或更高版本中删除UINavigationBar背景,您应该这样做:
[navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你
我相信这是 iOS5 的第一个实际答案,主要问题是完成后背景图像的“删除”。好吧,只需保留现有图像并在完成后将其放回去即可。
@implementation MyViewController {
UIImage *_defaultImage;
}
- (void)viewWillAppear:(BOOL)animated {
_defaultImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bar.png"] forBarMetrics:UIBarMetricsDefault];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController.navigationBar setBackgroundImage:_defaultImage forBarMetrics:UIBarMetricsDefault];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8316 次 |
| 最近记录: |