UINavigationBar appearance refresh?

前端 未结 3 711
情书的邮戳
情书的邮戳 2020-12-30 00:43

In my iPad app I have an application settings view. One of the options lets the user switch interface color scheme. The settings view is loaded by segue to a separate view

相关标签:
3条回答
  • 2020-12-30 01:33

    Objective-C:

    self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBarHidden = NO;
    

    Swift:

    self.navigationController?.isNavigationBarHidden = true
    self.navigationController?.isNavigationBarHidden = false
    
    0 讨论(0)
  • 2020-12-30 01:38

    While I think Aaron Brager's answer is the ideal appraoch, my app needs about 15 different appearance settings and uses a split view controller, so I have to reapply all the setting to the global appearance and then apply them all to my two displayed views. That's a lot of redundant code.

    Based on the idea that presenting and dismissing a modal view controller forces everything below it to redraw, I tried this and it worked perfectly:

    UIViewController *redrawTrigger = [[UIViewController alloc] init];
    redrawTrigger.modalPresentationStyle = UIModalPresentationFullScreen;
    [mySplitViewController presentModalViewController:redrawTrigger animated:FALSE];
    [mySplitViewController dismissModalViewControllerAnimated:FALSE];
    [redrawTrigger release];
    
    0 讨论(0)
  • 2020-12-30 01:40

    The appearance proxy only affects the look of newly initialized views. Setting colors on the appearance proxy will have no effect on navigation bars that are already visible.

    You'll need to manually update your current view; for example:

    self.navigationController.navigationBar.barTintColor = [UINavigationBar appearance].barTintColor;
    
    0 讨论(0)
提交回复
热议问题