UINavigationBar appearance refresh?

强颜欢笑 提交于 2019-11-30 08:13:17

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;
zaolian

Objective-C:

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

Swift:

self.navigationController?.isNavigationBarHidden = true
self.navigationController?.isNavigationBarHidden = false

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!