Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement night mode in Mac (Cocoa) application?

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!

like image 727
meetpd Avatar asked May 21 '16 06:05

meetpd


People also ask

How do I set my Mac to night mode?

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.

How do I make certain apps darker on Mac?

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.

How do you integrate dark mode?

Use the system setting (Settings -> Display -> Theme) to enable Dark theme.


1 Answers

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"

View Effects inspector

In Content Filters, click on the "+" icon and add and scroll to "Color Effect" / "Sepia Tone"

Content Filters

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).

before after

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.

like image 191
Fábio Palmeira Avatar answered Sep 22 '22 06:09

Fábio Palmeira