This commit is contained in:
Zhuoran Tan 2020-06-15 17:05:04 +08:00
Родитель e26dbe4291
Коммит 2246170e76
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#import "UIImage+DarkModeKit.h"
#import "DMDynamicImage.h"
#import "DMDarkModeManager.h"
#import "DMTraitCollection.h"
@import ObjectiveC;
@ -39,9 +40,14 @@
+ (UIImage *)dm_imageWithLightImage:(UIImage *)lightImage darkImage:(UIImage *)darkImage {
if (@available(iOS 13, *)) {
if (DMDarkModeManager.interoperableWithUIKit) {
UIImage *image = [lightImage copy];
[image.imageAsset registerImage:darkImage withTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]];
return image;
UITraitCollection *lightTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
UITraitCollection *darkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
UIImageAsset *imageAsset = [[UIImageAsset alloc] init];
[imageAsset registerImage:lightImage withTraitCollection:lightTraitCollection];
[imageAsset registerImage:darkImage withTraitCollection:darkTraitCollection];
return [imageAsset imageWithTraitCollection:(UITraitCollection *)DMTraitCollection.currentTraitCollection];
}
}