Last active
May 6, 2021 00:47
-
-
Save iccir/c0b0f69d71e272e07ead2f631a4df942 to your computer and use it in GitHub Desktop.
iOS Dark Mode Toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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
Xcode has a nice Environment Overrides pop-up, but I find this to be way more convenient.