macOS development - Dark Mode Dark Mode (10.14 mojave)


I, on the dark mode

This year's WWDC has published macOS 10.15, mojave have last year's version of the system, only recently adapted more attention to dark mode. Benefit is that we have written the article, so the following excerpt summarizes the contents are, first paste the address bar:

  • Support your dark mode
    https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface?language=objc

  • How to enable “real dark mode” on OS X / macOS
    https://medium.com/@guilhermerambo/how-to-enable-real-dark-mode-on-os-x-macos-14966f9f7d24

  • Dark Side of the Mac: Updating Your App
    https://mackuba.eu/2018/07/10/dark-side-mac-2/

https://stackoverflow.com/questions/37359825/how-do-i-implement-night-mode-in-mac-cocoa-application

http://www.sohu.com/a/256885010_115785

  • TomatosX: to determine whether the dark gray OS X menu bar (status bar) and the Dock
    https://www.jianshu.com/p/91400658a63b

Second, a command line enable / disable dark mode

defaults write -g NSRequiresAquaSystemAppearance -bool No

Close an application of the dark mode:

defaults write com.google.Chrome NSRequiresAquaSystemAppearance -bool YES  //关闭深色模式

defaults write com.google.Chrome NSRequiresAquaSystemAppearance -bool NO //启用

defaults write -g NSWindowDarkChocolate -bool TRUE  

defaults write -g NSWindowDarkChocolate -bool FALSE

Third, the pattern detecting darkness

1, the command line defaults read -g AppleInterfaceStyle

Dark dark mode Returns

$ defaults read -g AppleInterfaceStyle
Dark

Non-dark pattern

$ defaults read -g AppleInterfaceStyle
2019-06-12 15:04:55.644 defaults[9672:767112] 
The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist


2, the code AppleInterfaceStyle


NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle”];

NSLog(@"osxMode : %@",osxMode);  //黑暗模式打印:Dark  非黑暗模式: (null)

Third, the application does not use the dark mode

Many applications do not require the use of black models, but in the black mode, the window frame may be black, or any other font rendering issues. You need the following settings:

Add the key to the info.plist:
NSRequiresAquaSystemAppearanceset to YES, i.e., without using the dark mode.


Switching notification four black mode

Black user switching mode, the system will notify. Some junior partner application can be modified according to the notice.

[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
-(void)darkModeChanged:(NSNotification *)notif {
    NSLog(@"Dark mode changed");
}

V. Other

Dark sidebar under 1, non-dark pattern

https://github.com/rensbreur/DarkSidebar/blob/master/screenshot.png

Here Insert Picture Description


Published 164 original articles · won praise 162 · Views 650,000 +

Guess you like

Origin blog.csdn.net/lovechris00/article/details/91820404