iOS 暗黑模式适配


在需要处理暗黑模式的地方,再添加上如下代码:(设置相应配色)

if (@available(iOS 13.0, *)) {
    UIColor * rightColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trainCollection) {
        if ([trainCollection userInterfaceStyle] == UIUserInterfaceStyleLight) { //浅色模式
            return [UIColor whiteColor];
        } else { //深色模式
            return [UIColor blackColor];
        }
    }];
    self.bgView.backgroundColor = rightColor; //根据当前模式(光明\暗黑)-展示相应颜色 关键是这一句
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM