How to implement night mode in a Mac application (Cocoa)?

I am new to creating apps on Mac (Cocoa).

Can someone give me pointers on how I can create the night mode function in a Mac application?

I really appreciate your help in this regard.

Thanks!

+6
source share
1 answer

To get the filter in night mode, you need to reduce the effect of blue light (sunlight contains blue light and does not allow us to stay awake and warn).

The easiest way to remove blue light from your entire application is using a Content Filter in your views, in my case I use a sepia tone.

Select "View" and go to the "View Inspector"

Effect Presentation Inspector

In Content Filters, click the “+” icon and add and scroll to “Color Effect” / “Sepia Tones”

Content Filters

You can adjust the sepia tone or select different color filters to try to achieve the desired effect, but remember that the main goal is to remove the blue light (a sufficiently intense sepia tone with an intensity of 1).

before after

If you want to create a filter programmatically:

#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: Link to Basic Image Filters

Note. Some applications have added a red tint to all application views, but you may encounter some user interaction issues.

+2
source

All Articles