暗黑模式iOS13写在color分类里可以 写在自己的common文件里也可以

+ (UIColor *)lightColor:(UIColor *)lightC darkColor:(UIColor *)darkC
{
    if (@available(iOS 13.0, *)) {
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trait) {
            if (trait.userInterfaceStyle == UIUserInterfaceStyleDark) {
                return darkC;
            }
            else {
                return lightC;
            }
        }];
    }
    else {
        return lightC;
    }
}

温馨提示,像textField和textView的背景颜色  会自动适配dark和light  如果不想要改变   就得设置clearColor

猜你喜欢

转载自blog.csdn.net/cola_wh/article/details/105860612