最简单的方案:禁用
1: 在App内禁用深色模式: 可以在Info.plist(全局) 中,设置 User Interface Style 为 Light。
2: 在单个页面内禁用深色模式使用overrideUserInterfaceStyle: self.overrideUserInferfaceStyle = UIUserInterfaceStyleLight。
3: 在单个页面内禁用浅色模式使用overrideUserInterfaceStyle: self.overrideUserInferfaceStyle = UIUserInterfaceStyleDark。
适配方案:
首先获取app处于那种样式下,由于UIView,UIWindow, UIController 继承了UITraitEnvironment协议。故通过 self.traitCollection.userInterfaceStyle 来获取。
1:适配颜色
使用动态颜色
- (UIColor *)dynamicColor {
if (@available(ios 10.0, *)) {
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
return [UIColor whiteColor];
}else {
return [UIColor systemBlueColor];
}
}else {
return [UIColor systemBlueColor];
}
}
2:适配图片
在Assets.xcassets 中添加一套Dark模式下的图片

3:适配模糊效果
UIVibrancyEffect 模糊效果
UIVibrancyEffect 模糊效果加上鲜亮化效果(模糊效果上面的文字亮度有变化)
4:LaunchScreen.storyboard 中会有模式切换 但是Assets.xcassets中的LaunchImage不行。