1.如果你的项目之前禁用了深色模式,在plist中请删除这一项
image.png
- UIColor
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);
给UIColor 增加一个分类
+(UIColor *)colorWithDarkModeColor:(UIColor *)darkColor normalColor:(UIColor *)color{
if (@available(iOS 13.0,*)) {
if (darkColor) {
UIColor *dyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trainCollection) {
if ([trainCollection userInterfaceStyle] == UIUserInterfaceStyleDark) {
return darkColor;
}
else {
return color;
}
}];
return dyColor;
}
return color;
}
return color;
}
网友评论