At my main view, that contains a menu, I have an image on the navigationbar. When I select one of the menu items, I want to remove the background image and set text, normally.
When the second view opens, the background image still there. I tried everything, following some answers on StackOverflow, but still getting the same error.
I tried this:
- (void)viewWillDisappear:(BOOL)animated
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36, 36), NO, 0.0);
UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setBackgroundImage:blank forBarMetrics:UIBarMetricsDefault];
[super viewWillDisappear:animated];
}
Didn't work. Tried this:
@implementation ViewController{
UIImage *_bgNavigationBarImage;
}
- (void) viewWillAppear:(BOOL)animated {
_bgNavigationBarImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation-bar-home.png"] forBarMetrics:UIBarMetricsDefault];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController.navigationBar setBackgroundImage:_bgNavigationBarImage forBarMetrics:UIBarMetricsDefault];
[super viewWillDisappear:animated];
}
Didn't work too. Tried to set nil to background and still doesn't working.
Done!
Used the first method, but changing this:
[[UINavigationBar appearance] setBackgroundImage:blank forBarMetrics:UIBarMetricsDefault];
for this:
[self.navigationController.navigationBar setBackgroundImage:blank forBarMetrics:UIBarMetricsDefault];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.