Apply UIAppearance immediately on the screen
I was looking for how to apply changes made with UIAppearance’s proxy method immediately.
I found a solution in a library UISS, that handles Stylesheets written with JSON format.
- (void)refreshViews {
[[NSNotificationCenter defaultCenter] postNotificationName:UISSWillRefreshViewsNotification object:self];
for (UIWindow *window in [UIApplication sharedApplication].windows) {
for (UIView *view in window.subviews) {
[view removeFromSuperview];
[window addSubview:view];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:UISSDidRefreshViewsNotification object:self];
}
This code detaches all subviews of window
and attach them again.
I also tried setNeedsDisplay
and setNeedsLayout
, but didn’t work. So I adapted this hack.
Here is Swift version.
public func resetViews() {
let windows = UIApplication.sharedApplication().windows as [UIWindow]
for window in windows {
let subviews = window.subviews as [UIView]
for v in subviews {
v.removeFromSuperview()
window.addSubview(v)
}
}
}