iOS获取当前是深色还是浅色模式

UIUserInterfaceStyle style = UITraitCollection.currentTraitCollection.userInterfaceStyle;

根据模式设置颜色

UIColor *color = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
        if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
            return [UIColor yellowColor];
        }
        else {
            return [UIColor redColor];
        }
    }];

你可能感兴趣的:(iOS获取当前是深色还是浅色模式)