使用UIAppearance和切换主题 [英] Using UIAppearance and switching themes

查看:116
本文介绍了使用UIAppearance和切换主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找主题我的iOS应用程序,并一直在阅读UIAppearance。我希望用户能够在应用程序内切换许多不同的视觉主题。然后,UI中将显示更改主题。

I'm looking to theme my iOS app and have been reading up on UIAppearance. I want the user to be able to switch between a number of different visual themes from within the app. Changing a theme would then be shown in the UI.

我想我可以在appDelegate.m中加载一个单独的主题文件。但在那之后我有点坚持如何实现这个?

I'm thinking I could have a theme file that is a singleton loaded within the appDelegate.m. But after that i'm a little stuck on how this could be implemented?

推荐答案

UIKit在视图后从UIAppearance代理设置属性添加到视图层次结构。

UIKit sets properties from UIAppearance proxy after view is added to views hierarchy.

UISS 中,我使用如下方法:

In UISS I use method like this:

- (void)reloadAppearance {
    NSArray * windows = [UIApplication sharedApplication].windows;

    for (UIWindow *window in windows) {
        for (UIView *view in window.subviews) {
            [view removeFromSuperview];
            [window addSubview:view];
        }
    }
}

另一个技巧是删除rootViewController从主窗口再次添加。虽然我更喜欢第一种解决方案,因为它涵盖了更广泛的案例。

Another trick is to remove rootViewController from main window and add it again. Though I prefer the first solution, because it covers wider range of cases.

这篇关于使用UIAppearance和切换主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆