美文网首页
iOS实战之导航栏

iOS实战之导航栏

作者: SuAdrenine | 来源:发表于2017-01-12 14:33 被阅读21次

1、隐藏和显示导航栏

方法一:(简单粗暴)

- (void)viewWillAppear:(BOOL)animated { 
  [super viewWillAppear:animated]; 
  [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated { 
  [super viewWillDisappear:animated]; 
  [self.navigationController setNavigationBarHidden:NO animated:YES];
}

方法二:(使用代理)

//UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
  BOOL isHiddenNavBar = [viewController isKindOfClass:[self class]]; 
  [self.navigationController setNavigationBarHidden:isVC animated:YES];
}

2、自定义UINavigationController返回按钮

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    ViewController *vc = [ViewController new];
    UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:vc];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"返回";
    vc.navigationItem.backBarButtonItem = backItem;
    self.window.rootViewController = navC;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    return YES;
}

相关文章

网友评论

      本文标题:iOS实战之导航栏

      本文链接:https://www.haomeiwen.com/subject/nqwdbttx.html