From d67aebeeed5b0ab8fb56d24e3cd63ec5c5cb9d0d Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 10 Jun 2019 21:20:25 +0800 Subject: [PATCH] Fix that macOS indicator always use dynamic mode. Now only the `largeIndicator` and `mediumIndicator` supports dynamic dark mode switch --- Examples/SDWebImage OSX Demo/ViewController.m | 1 + SDWebImage/SDWebImageIndicator.h | 6 ++++-- SDWebImage/SDWebImageIndicator.m | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Examples/SDWebImage OSX Demo/ViewController.m b/Examples/SDWebImage OSX Demo/ViewController.m index dad6ae37..9463d81d 100644 --- a/Examples/SDWebImage OSX Demo/ViewController.m +++ b/Examples/SDWebImage OSX Demo/ViewController.m @@ -35,6 +35,7 @@ self.imageView1.sd_imageIndicator = SDWebImageProgressIndicator.defaultIndicator; [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_2.jpg"] placeholderImage:nil options:SDWebImageProgressiveLoad]; // NSImageView + Animated Image + self.imageView2.sd_imageIndicator = SDWebImageActivityIndicator.largeIndicator; [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng"]]; // SDAnimatedImageView + Static Image [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png"]]; diff --git a/SDWebImage/SDWebImageIndicator.h b/SDWebImage/SDWebImageIndicator.h index 1bce1e38..e1165c12 100644 --- a/SDWebImage/SDWebImageIndicator.h +++ b/SDWebImage/SDWebImageIndicator.h @@ -66,6 +66,7 @@ */ @interface SDWebImageActivityIndicator (Conveniences) +/// These indicator use the fixed color without dark mode support /// gray-style activity indicator @property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayIndicator; /// large gray-style activity indicator @@ -74,9 +75,10 @@ @property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteIndicator; /// large white-style activity indicator @property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteLargeIndicator; -/// large activity indicator, supports dark mode if available +/// These indicator use the system style, supports dark mode if available (iOS 13+/macOS 10.14+) +/// large activity indicator @property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *largeIndicator; -/// medium activity indicator, supports dark mode if available +/// medium activity indicator @property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *mediumIndicator; @end diff --git a/SDWebImage/SDWebImageIndicator.m b/SDWebImage/SDWebImageIndicator.m index 10b50620..458c38a5 100644 --- a/SDWebImage/SDWebImageIndicator.m +++ b/SDWebImage/SDWebImageIndicator.m @@ -93,6 +93,8 @@ static NSInteger UIActivityIndicatorViewStyleLarge = 101; #else indicator.indicatorView.color = [UIColor colorWithWhite:0 alpha:0.45]; // Color from `UIActivityIndicatorViewStyleGray` #endif +#else + indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support #endif return indicator; } @@ -104,6 +106,7 @@ static NSInteger UIActivityIndicatorViewStyleLarge = 101; indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; indicator.indicatorView.color = grayColor; #else + indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support indicator.indicatorView.controlSize = NSControlSizeRegular; #endif [indicator.indicatorView sizeToFit]; @@ -115,6 +118,7 @@ static NSInteger UIActivityIndicatorViewStyleLarge = 101; #if SD_UIKIT indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite; #else + indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support CIFilter *lighten = [CIFilter filterWithName:@"CIColorControls"]; [lighten setDefaults]; [lighten setValue:@(1) forKey:kCIInputBrightnessKey]; @@ -128,6 +132,7 @@ static NSInteger UIActivityIndicatorViewStyleLarge = 101; #if SD_UIKIT indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; #else + indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support indicator.indicatorView.controlSize = NSControlSizeRegular; [indicator.indicatorView sizeToFit]; #endif