最簡單的方案:禁用
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不行。
