Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UIAppearance and switching themes

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.

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?

like image 802
JMWhittaker Avatar asked Jun 12 '13 16:06

JMWhittaker


1 Answers

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.

like image 155
Robert Wijas Avatar answered Oct 08 '22 01:10

Robert Wijas