ios – 强制视图控制器重新加载以刷新UIAppearance更改

我一直在寻找一段时间,找不到答案.我在一个 IOS应用程序,并有一个模式设置页面出现在按钮的按钮,并返回与一个segue.
我想实现的一个选项是配色方案设置.我真的想避免手动更改页面上每个元素的颜色.

苹果有这样的事情的UIAppearance协议(所以我可以设置所有按钮的文本颜色等.
他们的文件说:

Note: iOS applies appearance changes when a view enters a window,it doesn’t change the appearance of a view that’s already in a window. To change the appearance of a view that’s currently in a window,remove the view from the view hierarchy and then put it back.

我的问题是如何做到这一点.我试过调用viewWillAppear和setNeedsDisplay没有运气.

解决方法

尝试使用此代码段:
NSArray *windows = [UIApplication sharedApplication].windows;
for (UIWindow *window in windows) {
    for (UIView *view in window.subviews) {
        [view removeFromSuperview];
        [window addSubview:view];
    }
}

http://snipplr.com/view/75259/refresh-uiappearance-after-application-loaded/

在使用UIAppearance更改应用主题后,它对我来说是完美的

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...