简体   繁体   中英

change navigationbar on only one view

I have set a custom navigationbar in my appdelegate. You can see the code over here.

UIImage *image = [UIImage imageNamed:@"navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

But now I'm working with the eventkit framework. What I want is when I go to eventdetails, that I get the standard navbar layout.So without the image.

EKEventViewController *vc = [[EKEventViewController alloc] init];
[vc.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
vc.event = [dataSource eventAtIndexPath:indexPath];
vc.allowsEditing = YES;
[calendar.navigationController pushViewController:vc animated:YES];

I've tried the following but it is not working. Any help?

you can do one thing, take the screenshot of one viewController with default navigation bar , just crop only navigation bar area ie make image of 320 x 44 size.

when you want again your by default navigation bar , that time use this cropped image as background of navigation bar ,add following code

UIImage *image = [UIImage imageNamed:@"defaultNavbar.png"];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

again when you navigate to another viewController having custom Navimage then again draw nav image by help of your custom image code ie

UIImage *image = [UIImage imageNamed:@"navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:image 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.

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