From 2246170e767b95cb581b523653fc752603e925f6 Mon Sep 17 00:00:00 2001 From: Zhuoran Tan Date: Mon, 15 Jun 2020 17:05:04 +0800 Subject: [PATCH] Use UIImageAsset for UIImage --- Sources/DarkModeCore/UIImage+DarkModeKit.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/DarkModeCore/UIImage+DarkModeKit.m b/Sources/DarkModeCore/UIImage+DarkModeKit.m index a580d8a..53bcc4c 100644 --- a/Sources/DarkModeCore/UIImage+DarkModeKit.m +++ b/Sources/DarkModeCore/UIImage+DarkModeKit.m @@ -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]; } }