Using UIAppearance and switching themes

前端 未结 4 662
囚心锁ツ
囚心锁ツ 2021-01-06 05:26

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 a

4条回答
  •  隐瞒了意图╮
    2021-01-06 06:00

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

    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];
            }
        }
    }
    

    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.

提交回复
热议问题