1、 图片适配
2、颜色适配(文字颜色,背景颜色)
3、状态栏适配
4、关闭暗⿊模式(或者关闭某⼀个页⾯的暗⿊模式)
5、模式切换代理

系统提供的动态颜色有: labelColor、systemBackgroundColor、secondarySystemBackgroundColor、tertiarySystemBackgroundColor、systemGroupedBackgroundColor、secondarySystemGroupedBackgroundColor、tertiarySystemGroupedBackgroundColor等。
1、iOS13苹果提供了两个专⽤的⽅法:
+ (UIColor *)colorWithDynamicProvider:(UIColor * (^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
- (UIColor *)initWithDynamicProvider:(UIColor * (^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
#import "UIColor+DarkAndLightColor.h"
@implementation UIColor (DarkAndLightColor)
+ (UIColor *)colorWithLight:(UIColor *)lightColor dark:(UIColor *)darkColor {
if (@available( iOS 13.0, *)) {
return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
return darkColor;
} else {
return lightColor;
}
}];
} else {
return lightColor;
}
}
@end
2、可以在 Assets.xcassets 文件中使用使用 ColorSet 直接动态设置不同模式下的颜色。


- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"SecondViewController";
self.view.backgroundColor = [UIColor systemBackgroundColor];
//设置当前控制器不遵循暗黑模式
if (@available( iOS 13.0, *)) {
self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
} else {
NSLog(@"版本低于 iOS 13.0 ");
}
}
//需要监听系统暗黑模式切换的,看如下代理
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
if (@available(iOS 13.0, *)) {
if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
NSLog(@"当前界面处于暗黑模式");
} else {
NSLog(@"当前模式处于Light模式");
}
}
}