Update to support gray & grayLarge on iOS & tvOS

This commit is contained in:
DreamPiggy 2018-02-04 16:40:22 +08:00
parent 89babbbfbe
commit e873255b16
2 changed files with 17 additions and 13 deletions

View File

@ -59,9 +59,9 @@
@interface SDWebImageActivityIndicator (Conveniences)
/// gray-style activity indicator
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayIndicator API_UNAVAILABLE(tvos);
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayIndicator;
/// large gray-style activity indicator
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayLargeIndicator API_UNAVAILABLE(ios, tvos);
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayLargeIndicator;
/// white-style activity indicator
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteIndicator;
/// large white-style activity indicator

View File

@ -38,12 +38,7 @@
#if SD_UIKIT
- (void)commonInit {
#if SD_TV
UIActivityIndicatorViewStyle style = UIActivityIndicatorViewStyleWhite;
#else
UIActivityIndicatorViewStyle style = UIActivityIndicatorViewStyleGray;
#endif
self.indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style];
self.indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.indicatorView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
}
#endif
@ -80,21 +75,30 @@
@implementation SDWebImageActivityIndicator (Conveniences)
#if SD_MAC || SD_IOS
+ (SDWebImageActivityIndicator *)grayIndicator {
SDWebImageActivityIndicator *indicator = [SDWebImageActivityIndicator new];
#if SD_UIKIT
#if SD_IOS
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
#else
indicator.indicatorView.color = [UIColor colorWithWhite:0 alpha:0.45]; // Color from `UIActivityIndicatorViewStyleGray`
#endif
#endif
return indicator;
}
#endif
#if SD_MAC
+ (SDWebImageActivityIndicator *)grayLargeIndicator {
SDWebImageActivityIndicator *indicator = SDWebImageActivityIndicator.grayIndicator;
#if SD_UIKIT
UIColor *grayColor = indicator.indicatorView.color;
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
indicator.indicatorView.color = grayColor;
#else
indicator.indicatorView.controlSize = NSControlSizeRegular;
#endif
[indicator.indicatorView sizeToFit];
return indicator;
}
#endif
+ (SDWebImageActivityIndicator *)whiteIndicator {
SDWebImageActivityIndicator *indicator = [SDWebImageActivityIndicator new];
@ -153,7 +157,7 @@
#if SD_MAC
- (void)commonInit {
self.indicatorView = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 160, 0)];
self.indicatorView = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 160, 0)]; // Width from `UIProgressView` default width
self.indicatorView.style = NSProgressIndicatorStyleBar;
self.indicatorView.controlSize = NSControlSizeSmall;
[self.indicatorView sizeToFit];