一、关闭
1.怎么全局关闭
在plist文件中加入下面这两句话
<key>UIUserInterfaceStyle</key>
<string>Light</string>
2.怎么关闭某个页面
在Controller中加入下面这句话
self.view.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
二、适配
1.在xcassets中适配
image.png选中一个图片,Option+Command+4,将Apperances 选项 改为Any,Dark
2.使用代码适配
+ (UIColor *)colorWithDynamicProvider:(UIColor * (^)(UITraitCollection *))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
- (UIColor *)initWithDynamicProvider:(UIColor * (^)(UITraitCollection *))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
例如:
UIColor *color = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
return [UIColor whiteColor];
} else {
return [UIColor redColor];
}
}];
self.titleLabel.textColor = color;
网友评论