Skip to content

Instantly share code, notes, and snippets.

@muskingo muskingo/darkmode.m forked from iccir/darkmode.m
Created Jun 10, 2019

Embed
What would you like to do?
iOS Dark Mode Toggle
/*
During Dark Mode migration for macOS, I found it helpful to have a global hotkey
which toggled between Light/Dark Mode.
This hack attempts to do something similar for iOS.
1) Add your main window in -applicationDidFinishLaunching:
2) Triple tap the window (I tend to do this near the title bar) to flip between light and dark.
*/
#if DEBUG
@interface UIApplication ()
+ (void) _setDebugUserInterfaceStyleOverride:(NSInteger)override;
@end
@implementation UIApplication (IccirDebugUserInterfaceStyleOverride)
- (void) iccirToggleDebugUserInterfaceStyleOverride
{
static NSInteger sOverride = 0;
sOverride = sOverride == 1 ? 2 : 1;
[UIApplication _setDebugUserInterfaceStyleOverride:sOverride];
}
@end
void AddInterfaceStyleToggle(UIWindow *window)
{
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] init];
[recognizer setNumberOfTapsRequired:3];
[recognizer addTarget:[UIApplication sharedApplication] action:@selector(iccirToggleDebugUserInterfaceStyleOverride)];
[window addGestureRecognizer:recognizer];
}
#else
void AddInterfaceStyleToggle(UIWindow *window) { }
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.