I am new to creating apps on Mac (Cocoa).
Can someone give me pointers on how can I create a night mode feature in a Mac App?
I really appreciate your help in this regards.
Thanks!
On your Mac, choose Apple menu > System Preferences, click Displays , then click Night Shift. Select Manual to turn on Night Shift. Night Shift remains on until the next day or until you turn it off.
Turn on Dark ModeChoose Apple menu > System Preferences, click General, then select one of the Appearance options at the top of the window: Light: Use the light appearance. Dark: Use the dark appearance. Auto: Automatically use the light appearance during the day, and the dark appearance at night.
Use the system setting (Settings -> Display -> Theme) to enable Dark theme.
To achieve a night-mode filter, you need to reduce the exposure to the blue light (sunlight contains blue light and keep us awake and alert).
The most simple way to remove blue light on your entire app it's use a Content Filter on your Views, in my case I use sepia tone.
Select your View and go to the "View Effects inspector"
In Content Filters, click on the "+" icon and add and scroll to "Color Effect" / "Sepia Tone"
You can adjust the Sepia Tone or pick different color filters to try to achieve a desired effect, but remember the main goal is remove the blue light (Sepia Tone with intensity 1 is enough).
If you want to programaticly way to create a filter:
#import "ViewController.h"
#import <CoreImage/CIFilter.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CIFilter * sepiaTone = [CIFilter filterWithName:@"CISepiaTone" keysAndValues:@"inputIntensity", @1.0, nil];
self.view.contentFilters = [NSArray arrayWithObject:sepiaTone];
}
Apple Reference: Core Image Filters Reference
Note: Some apps put a red hue layer upon all application Views but you can face some problems with user interactions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With