Not suitable for dark color mode

Add a new field directly to info

User Interface Style

Set values for the

Light

Match dark mode

You don’t need to add the field in info for black mode

But you need to in each UIWindow, UIViewController, UIView inside increases the method below

-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection

Use this method to determine and change the colors of all elements in the current interface

I made a singleton to store all the colors in the application separately

There are two other methods, respectively, is to change all the colors to the corresponding light or dark

Light is one Color value, dark is another Color value, an application can define multiple colors

All the colors of the application are taken from this singleton

All you have to do is refresh the interface to change the order

-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
    [super traitCollectionDidChange: previousTraitCollection];
    if(@ the available (iOS 13.0, *)) {if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark)
        {
            [[Color darkColor] setDarkColorArray];
            LRLog(@"Dark Mode");
        }
        else
        {
            [[Color darkColor] setBrightColorArray];
            LRLog(@"Normal mode");
        }
        UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[Color darkColor].dataColor2,NSFontAttributeName:[UIFont systemFontOfSize:18]}];
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[Color darkColor].backColor] forBarMetrics:(UIBarMetricsDefault)];
        [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[Color darkColor].backColor]];
        [self.navigationController.navigationBar setBarTintColor:[Color darkColor].backColor]; window.backgroundColor=[Color darkColor].backColor; self.view.backgroundColor=[Color darkColor].backColor; }}Copy the code

The next step is icon adaptation

Icon words need to prepare two sets

A white one and a black one

Or change the colors yourself while preparing a set

One set of black and one set of white just add a picture below

A set of pictures to see the Demo

The Demo address github.com/YouZhiZheSh…