diff --git a/JGProgressHUD Tests/JGProgressHUD Tests/JGAppDelegate.m b/JGProgressHUD Tests/JGProgressHUD Tests/JGAppDelegate.m index 2fa934b..8db48b4 100644 --- a/JGProgressHUD Tests/JGProgressHUD Tests/JGAppDelegate.m +++ b/JGProgressHUD Tests/JGProgressHUD Tests/JGAppDelegate.m @@ -26,7 +26,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return YES; } - + - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. @@ -35,7 +35,7 @@ - (void)applicationWillResignActive:(UIApplication *)application - (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } diff --git a/JGProgressHUD Tests/JGProgressHUD Tests/JGViewController.m b/JGProgressHUD Tests/JGProgressHUD Tests/JGViewController.m index f3af890..fccf2d6 100644 --- a/JGProgressHUD Tests/JGProgressHUD Tests/JGViewController.m +++ b/JGProgressHUD Tests/JGProgressHUD Tests/JGViewController.m @@ -79,7 +79,7 @@ - (JGProgressHUD *)prototypeHUD { return HUD; } -- (void)success { +- (void)showSuccessHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.textLabel.text = @"Success!"; @@ -92,7 +92,7 @@ - (void)success { [HUD dismissAfterDelay:3.0]; } -- (void)error { +- (void)showErrorHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.textLabel.text = @"Error!"; @@ -105,7 +105,7 @@ - (void)error { [HUD dismissAfterDelay:3.0]; } -- (void)simple { +- (void)showSimpleHUD { JGProgressHUD *HUD = self.prototypeHUD; [HUD showInView:self.navigationController.view]; @@ -113,7 +113,7 @@ - (void)simple { [HUD dismissAfterDelay:3.0]; } -- (void)tapToCancel { +- (void)showCancellableHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.textLabel.text = @"Loading very long..."; @@ -173,7 +173,7 @@ - (void)tapToCancel { [HUD dismissAfterDelay:120.0]; } -- (void)withText { +- (void)showNormalHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.textLabel.text = @"Loading..."; @@ -192,68 +192,70 @@ - (void)withText { HUD.marginInsets = UIEdgeInsetsMake(0.0f, 0.0f, 10.0f, 0.0f); - [HUD dismissAfterDelay:3]; + [HUD dismissAfterDelay:3.0]; } -- (void)progress { +- (void)showPieHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.indicatorView = [[JGProgressHUDPieIndicatorView alloc] initWithHUDStyle:HUD.style]; - HUD.textLabel.text = @"Uploading..."; - [HUD showInView:self.navigationController.view]; + HUD.detailTextLabel.text = @"0% Complete"; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:0.25 animated:YES]; - }); + HUD.textLabel.text = @"Downloading..."; + [HUD showInView:self.navigationController.view]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:0.5 animated:YES]; - }); + HUD.layoutChangeAnimationDuration = 0.0; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:0.75 animated:YES]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self incrementHUD:HUD progress:0]; }); +} + +- (void)incrementHUD:(JGProgressHUD *)HUD progress:(int)progress { + progress += 1; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:1.0 animated:YES]; - }); + [HUD setProgress:progress/100.0f animated:NO]; + HUD.detailTextLabel.text = [NSString stringWithFormat:@"%i%% Complete", progress]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD dismiss]; - }); + if (progress == 100) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + HUD.textLabel.text = @"Success"; + HUD.detailTextLabel.text = nil; + + HUD.layoutChangeAnimationDuration = 0.3; + HUD.indicatorView = [[JGProgressHUDSuccessIndicatorView alloc] init]; + }); + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [HUD dismiss]; + }); + } + else { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self incrementHUD:HUD progress:progress]; + }); + } } -- (void)zoomAnimationWithRing { +- (void)showRingHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.indicatorView = [[JGProgressHUDRingIndicatorView alloc] initWithHUDStyle:HUD.style]; + HUD.detailTextLabel.text = @"0% Complete"; + HUD.textLabel.text = @"Downloading..."; [HUD showInView:self.navigationController.view]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:0.25 animated:YES]; - }); - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:0.5 animated:YES]; - }); - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:0.75 animated:YES]; - }); - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD setProgress:1.0 animated:YES]; - }); + HUD.layoutChangeAnimationDuration = 0.0; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HUD dismiss]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self incrementHUD:HUD progress:0]; }); } -- (void)textOnly { +- (void)showTextHUD { JGProgressHUD *HUD = self.prototypeHUD; HUD.indicatorView = nil; @@ -269,7 +271,7 @@ - (void)textOnly { [HUD showInView:self.navigationController.view]; - [HUD dismissAfterDelay:2.0f]; + [HUD dismissAfterDelay:2.0]; } - (void)setHUDStyle:(UISegmentedControl *)c { @@ -411,10 +413,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.textLabel.text = @"Activity Indicator & Text, Transform"; break; case 2: - cell.textLabel.text = @"Pie Progress"; + cell.textLabel.text = @"Pie Progress, Text & Detail Text"; break; case 3: - cell.textLabel.text = @"Ring Progress"; + cell.textLabel.text = @"Ring Progress, Text & Detail Text"; break; case 4: cell.textLabel.text = @"Text Only, Bottom Position"; @@ -444,28 +446,28 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath switch (indexPath.row) { case 0: - [self simple]; + [self showSimpleHUD]; break; case 1: - [self withText]; + [self showNormalHUD]; break; case 2: - [self progress]; + [self showPieHUD]; break; case 3: - [self zoomAnimationWithRing]; + [self showRingHUD]; break; case 4: - [self textOnly]; + [self showTextHUD]; break; case 5: - [self success]; + [self showSuccessHUD]; break; case 6: - [self error]; + [self showErrorHUD]; break; case 7: - [self tapToCancel]; + [self showCancellableHUD]; break; } } diff --git a/JGProgressHUD.podspec b/JGProgressHUD.podspec index df34d7b..06f1c25 100644 --- a/JGProgressHUD.podspec +++ b/JGProgressHUD.podspec @@ -1,14 +1,14 @@ Pod::Spec.new do |s| s.name = "JGProgressHUD" - s.version = "1.2" + s.version = "1.2.1" s.summary = "Powerful and modern progress HUD for iOS." s.homepage = "https://github.com/JonasGessner/JGProgressHUD" s.license = { :type => "MIT", :file => "LICENSE.txt" } s.author = "Jonas Gessner" s.social_media_url = "http://twitter.com/JonasGessner" s.platform = :ios, "5.0" - s.source = { :git => "https://github.com/JonasGessner/JGProgressHUD.git", :tag => "v1.2" } + s.source = { :git => "https://github.com/JonasGessner/JGProgressHUD.git", :tag => "v1.2.1" } s.source_files = "JGProgressHUD/JGProgressHUD/*.{h,m}" s.resources = "JGProgressHUD/JGProgressHUD/JGProgressHUD Resources.bundle" s.frameworks = "Foundation", "UIKit", "QuartzCore" diff --git a/JGProgressHUD/JGProgressHUD.xcodeproj/project.pbxproj b/JGProgressHUD/JGProgressHUD.xcodeproj/project.pbxproj index 80badb6..db9784d 100644 --- a/JGProgressHUD/JGProgressHUD.xcodeproj/project.pbxproj +++ b/JGProgressHUD/JGProgressHUD.xcodeproj/project.pbxproj @@ -333,6 +333,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; + WARNING_CFLAGS = ""; WRAPPER_EXTENSION = bundle; }; name = Debug; @@ -349,6 +350,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; + WARNING_CFLAGS = ""; WRAPPER_EXTENSION = bundle; }; name = Release; @@ -430,6 +432,7 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + WARNING_CFLAGS = "-Wfloat-equal"; }; name = Debug; }; @@ -442,6 +445,7 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + WARNING_CFLAGS = "-Wfloat-equal"; }; name = Release; }; @@ -455,6 +459,7 @@ 6B60B24619A3B3C500ED1A4E /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 6BC0186E197B2AA500DA4C49 /* Build configuration list for PBXProject "JGProgressHUD" */ = { isa = XCConfigurationList; diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUD.h b/JGProgressHUD/JGProgressHUD/JGProgressHUD.h index 0c4756a..5c34f93 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUD.h +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUD.h @@ -45,7 +45,6 @@ typedef NS_ENUM(NSUInteger, JGProgressHUDInteractionType) { JGProgressHUDInteractionTypeBlockNoTouches }; - @class JGProgressHUD; @protocol JGProgressHUDDelegate @@ -137,6 +136,11 @@ typedef NS_ENUM(NSUInteger, JGProgressHUDInteractionType) { */ @property (nonatomic, strong, readonly) UILabel *textLabel; +/** + The label used to present detail text on the HUD. set the @c text property of this label to change the displayed text. You may not change the label's @c frame or @c bounds. + */ +@property (nonatomic, strong, readonly) UILabel *detailTextLabel; + /** The indicator view. You can assign a custom subclass of JGProgressHUDIndicatorView to this property or one of the default indicator views (if you do so, you should assign it before showing the HUD). @@ -335,3 +339,11 @@ typedef NS_ENUM(NSUInteger, JGProgressHUDInteractionType) { @property (nonatomic, assign) BOOL useProgressIndicatorView DEPRECATED_ATTRIBUTE; @end + + +/** + Macro for safe floating point comparison (for internal use in JGProgressHUD). + */ +#ifndef fequal +#define fequal(a,b) (fabs((a) - (b)) < FLT_EPSILON) +#endif diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUD.m b/JGProgressHUD/JGProgressHUD/JGProgressHUD.m index 16dba73..0b94d7a 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUD.m +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUD.m @@ -66,6 +66,7 @@ @implementation JGProgressHUD @synthesize HUDView = _HUDView; @synthesize textLabel = _textLabel; +@synthesize detailTextLabel = _detailTextLabel; @synthesize indicatorView = _indicatorView; @synthesize animation = _animation; @@ -213,30 +214,52 @@ - (void)updateHUDAnimated:(BOOL)animated animateIndicatorViewFrame:(BOOL)animate //Label size CGRect labelFrame = CGRectZero; + CGRect detailFrame = CGRectZero; - if (iOS7) { - NSDictionary *attributes = @{NSFontAttributeName : self.textLabel.font}; - labelFrame.size = [self.textLabel.text boundingRectWithSize:maxContentSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size; - } - else { + if (_textLabel) { + if (iOS7) { + NSDictionary *attributes = @{NSFontAttributeName : self.textLabel.font}; + labelFrame.size = [self.textLabel.text boundingRectWithSize:maxContentSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size; + } + else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - labelFrame.size = [self.textLabel.text sizeWithFont:self.textLabel.font constrainedToSize:maxContentSize lineBreakMode:self.textLabel.lineBreakMode]; + labelFrame.size = [self.textLabel.text sizeWithFont:self.textLabel.font constrainedToSize:maxContentSize lineBreakMode:self.textLabel.lineBreakMode]; #pragma clang diagnostic pop + } + + labelFrame.origin.y = CGRectGetMaxY(indicatorFrame); + + if (!CGRectIsEmpty(labelFrame) && !CGRectIsEmpty(indicatorFrame)) { + labelFrame.origin.y += 10.0f; + } } - labelFrame.origin.y = CGRectGetMaxY(indicatorFrame); - - if (!CGRectIsEmpty(labelFrame) && !CGRectIsEmpty(indicatorFrame)) { - labelFrame.origin.y += 10.0f; + if (_detailTextLabel) { + if (iOS7) { + NSDictionary *attributes = @{NSFontAttributeName : self.detailTextLabel.font}; + detailFrame.size = [self.detailTextLabel.text boundingRectWithSize:maxContentSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size; + } + else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + detailFrame.size = [self.detailTextLabel.text sizeWithFont:self.detailTextLabel.font constrainedToSize:maxContentSize lineBreakMode:self.detailTextLabel.lineBreakMode]; +#pragma clang diagnostic pop + } + + detailFrame.origin.y = CGRectGetMaxY(labelFrame)+5.0f; + + if (!CGRectIsEmpty(detailFrame) && !CGRectIsEmpty(indicatorFrame) && CGRectIsEmpty(labelFrame)) { + detailFrame.origin.y += 5.0f; + } } //HUD size CGSize size = CGSizeZero; - CGFloat width = MIN(self.contentInsets.left+MAX(indicatorFrame.size.width, labelFrame.size.width)+self.contentInsets.right, self.frame.size.width-self.marginInsets.left-self.marginInsets.right); + CGFloat width = MIN(self.contentInsets.left+MAX(indicatorFrame.size.width, MAX(labelFrame.size.width, detailFrame.size.width))+self.contentInsets.right, self.frame.size.width-self.marginInsets.left-self.marginInsets.right); - CGFloat height = CGRectGetMaxY(labelFrame)+self.contentInsets.bottom; + CGFloat height = MAX(CGRectGetMaxY(labelFrame), MAX(CGRectGetMaxY(detailFrame), CGRectGetMaxY(indicatorFrame)))+self.contentInsets.bottom; if (self.square) { CGFloat uniSize = MAX(width, height); @@ -244,10 +267,11 @@ - (void)updateHUDAnimated:(BOOL)animated animateIndicatorViewFrame:(BOOL)animate size.width = uniSize; size.height = uniSize; - CGFloat heightDelta = uniSize-height; + CGFloat heightDelta = (uniSize-height)/2.0f; - labelFrame.origin.y += heightDelta/2.0f; - indicatorFrame.origin.y += heightDelta/2.0f; + labelFrame.origin.y += heightDelta; + detailFrame.origin.y += heightDelta; + indicatorFrame.origin.y += heightDelta; } else { size.width = width; @@ -258,6 +282,7 @@ - (void)updateHUDAnimated:(BOOL)animated animateIndicatorViewFrame:(BOOL)animate indicatorFrame.origin.x = center.x-indicatorFrame.size.width/2.0f; labelFrame.origin.x = center.x-labelFrame.size.width/2.0f; + detailFrame.origin.x = center.x-detailFrame.size.width/2.0f; void (^updates)(void) = ^{ [self setHUDViewFrameCenterWithSize:size]; @@ -265,7 +290,9 @@ - (void)updateHUDAnimated:(BOOL)animated animateIndicatorViewFrame:(BOOL)animate if (animateIndicator) { self.indicatorView.frame = indicatorFrame; } - self.textLabel.frame = labelFrame; + + _textLabel.frame = labelFrame; + _detailTextLabel.frame = detailFrame; }; if (!animateIndicator) { @@ -273,7 +300,7 @@ - (void)updateHUDAnimated:(BOOL)animated animateIndicatorViewFrame:(BOOL)animate } if (self.layoutChangeAnimationDuration > 0.0f && animated && !_transitioning) { - [UIView animateWithDuration:self.layoutChangeAnimationDuration delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:updates completion:nil]; + [UIView animateWithDuration:self.layoutChangeAnimationDuration delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionCurveEaseInOut animations:updates completion:nil]; } else { updates(); @@ -561,7 +588,7 @@ - (UILabel *)textLabel { _textLabel.backgroundColor = [UIColor clearColor]; _textLabel.textColor = (self.style == JGProgressHUDStyleDark ? [UIColor whiteColor] : [UIColor blackColor]); _textLabel.textAlignment = NSTextAlignmentCenter; - _textLabel.font = [UIFont boldSystemFontOfSize:14.0f]; + _textLabel.font = [UIFont boldSystemFontOfSize:15.0f]; _textLabel.numberOfLines = 0; [_textLabel addObserver:self forKeyPath:@"text" options:kNilOptions context:NULL]; [_textLabel addObserver:self forKeyPath:@"font" options:kNilOptions context:NULL]; @@ -572,6 +599,23 @@ - (UILabel *)textLabel { return _textLabel; } +- (UILabel *)detailTextLabel { + if (!_detailTextLabel) { + _detailTextLabel = [[UILabel alloc] init]; + _detailTextLabel.backgroundColor = [UIColor clearColor]; + _detailTextLabel.textColor = (self.style == JGProgressHUDStyleDark ? [UIColor whiteColor] : [UIColor blackColor]); + _detailTextLabel.textAlignment = NSTextAlignmentCenter; + _detailTextLabel.font = [UIFont systemFontOfSize:13.0f]; + _detailTextLabel.numberOfLines = 0; + [_detailTextLabel addObserver:self forKeyPath:@"text" options:kNilOptions context:NULL]; + [_detailTextLabel addObserver:self forKeyPath:@"font" options:kNilOptions context:NULL]; + + [self.contentView addSubview:_detailTextLabel]; + } + + return _detailTextLabel; +} + - (JGProgressHUDAnimation *)animation { if (!_animation) { self.animation = [JGProgressHUDFadeAnimation animation]; @@ -583,7 +627,7 @@ - (JGProgressHUDAnimation *)animation { #pragma mark - Setters - (void)setCornerRadius:(CGFloat)cornerRadius { - if (self.cornerRadius == cornerRadius) { + if (fequal(self.cornerRadius, cornerRadius)) { return; } @@ -663,7 +707,7 @@ - (void)setProgress:(float)progress { } - (void)setProgress:(float)progress animated:(BOOL)animated { - if (self.progress == progress) { + if (fequal(self.progress, progress)) { return; } @@ -693,7 +737,7 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (object == self.textLabel) { + if (object == _textLabel || object == _detailTextLabel) { [self updateHUDAnimated:YES animateIndicatorViewFrame:YES]; } else { @@ -706,6 +750,9 @@ - (void)dealloc { [_textLabel removeObserver:self forKeyPath:@"text"]; [_textLabel removeObserver:self forKeyPath:@"font"]; + + [_detailTextLabel removeObserver:self forKeyPath:@"text"]; + [_detailTextLabel removeObserver:self forKeyPath:@"font"]; } - (void)removeObservers { diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m b/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m index f78fd6e..35fe60c 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m @@ -7,6 +7,7 @@ // #import "JGProgressHUDIndicatorView.h" +#import "JGProgressHUD.h" @implementation JGProgressHUDIndicatorView @@ -42,7 +43,7 @@ - (void)setProgress:(float)progress { } - (void)setProgress:(float)progress animated:(BOOL)animated { - if (self.progress == progress) { + if (fequal(self.progress, progress)) { return; } diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.h b/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.h index f049b6d..fc8e775 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.h +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.h @@ -19,8 +19,15 @@ /** Tint color of the Pie. - @b Default: white. + @b Default: White for JGProgressHUDStyleDark, otherwise black. */ @property (nonatomic, strong) UIColor *color; +/** + The background fill color inside the pie. + + @b Default: Dark gray for JGProgressHUDStyleDark, otherwise light gray. + */ +@property (nonatomic, strong) UIColor *fillColor; + @end diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.m b/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.m index ef4dcce..3cd3a52 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.m +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUDPieIndicatorView.m @@ -14,14 +14,16 @@ @interface JGProgressHUDPieIndicatorLayer : CALayer @property (nonatomic, weak) UIColor *color; +@property (nonatomic, weak) UIColor *fillColor; + @end @implementation JGProgressHUDPieIndicatorLayer -@dynamic progress, color; +@dynamic progress, color, fillColor; + (BOOL)needsDisplayForKey:(NSString *)key { - return ([key isEqualToString:@"progress"] || [key isEqualToString:@"color"] || [super needsDisplayForKey:key]); + return ([key isEqualToString:@"progress"] || [key isEqualToString:@"color"] || [key isEqualToString:@"fillColor"] || [super needsDisplayForKey:key]); } - (id )actionForKey:(NSString *)key { @@ -46,14 +48,22 @@ - (void)drawInContext:(CGContextRef)ctx { CGFloat lineWidth = 2.0f; CGFloat radius = floorf(MIN(rect.size.width, rect.size.height) / 2.0f) -lineWidth; - [self.color setStroke]; - - //Border + //Border && Fill UIBezierPath *borderPath = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:0.0f endAngle:2*M_PI clockwise:NO]; [borderPath setLineWidth:lineWidth]; + + if (self.fillColor) { + [self.fillColor setFill]; + + [borderPath fill]; + } + + [self.color set]; + [borderPath stroke]; + //Progress if (self.progress) { UIBezierPath *processPath = [UIBezierPath bezierPath]; @@ -87,9 +97,16 @@ - (instancetype)initWithHUDStyle:(JGProgressHUDStyle)style { if (style == JGProgressHUDStyleDark) { self.color = [UIColor whiteColor]; + self.fillColor = [UIColor colorWithWhite:0.2f alpha:1.0f]; } else { self.color = [UIColor blackColor]; + if (style == JGProgressHUDStyleLight) { + self.fillColor = [UIColor colorWithWhite:0.85f alpha:1.0f]; + } + else { + self.fillColor = [UIColor colorWithWhite:0.9f alpha:1.0f]; + } } } @@ -121,8 +138,18 @@ - (void)setColor:(UIColor *)tintColor { [(JGProgressHUDPieIndicatorLayer *)self.layer setColor:self.color]; } +- (void)setFillColor:(UIColor *)fillColor { + if ([fillColor isEqual:self.fillColor]) { + return; + } + + _fillColor = fillColor; + + [(JGProgressHUDPieIndicatorLayer *)self.layer setFillColor:self.fillColor]; +} + - (void)setProgress:(float)progress animated:(BOOL)animated { - if (self.progress == progress) { + if (fequal(self.progress, progress)) { return; } diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.h b/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.h index 39a401c..7351f97 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.h +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.h @@ -19,14 +19,14 @@ /** Background color of the ring. - @b Default: black. + @b Default: Black for JGProgressHUDStyleDark, light gray otherwise. */ @property (nonatomic, strong) UIColor *ringBackgroundColor; /** Progress color of the progress ring. - @b Default: white. + @b Default: White for JGProgressHUDStyleDark, otherwise black. */ @property (nonatomic, strong) UIColor *ringColor; @@ -40,7 +40,7 @@ /** Width of the ring. - @b Default: 5.0 + @b Default: 3.0. */ @property (nonatomic, assign) CGFloat ringWidth; diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.m b/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.m index 5ff26bc..f3d8e40 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.m +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUDRingIndicatorView.m @@ -98,7 +98,12 @@ - (instancetype)initWithHUDStyle:(JGProgressHUDStyle)style { } else { self.ringColor = [UIColor blackColor]; - self.ringBackgroundColor = [UIColor colorWithWhite:0.95f alpha:1.0f]; + if (style == JGProgressHUDStyleLight) { + self.ringBackgroundColor = [UIColor colorWithWhite:0.85f alpha:1.0f]; + } + else { + self.ringBackgroundColor = [UIColor colorWithWhite:0.9f alpha:1.0f]; + } } } @@ -114,7 +119,7 @@ - (instancetype)initWithContentView:(UIView *)contentView { self.ringColor = [UIColor whiteColor]; self.ringBackgroundColor = [UIColor blackColor]; - self.ringWidth = 5.0f; + self.ringWidth = 3.0f; } return self; @@ -153,7 +158,7 @@ - (void)setRingBackgroundColor:(UIColor *)backgroundTintColor { } - (void)setRingWidth:(CGFloat)ringWidth { - if (ringWidth == self.ringWidth) { + if (fequal(ringWidth, self.ringWidth)) { return; } @@ -163,7 +168,7 @@ - (void)setRingWidth:(CGFloat)ringWidth { } - (void)setProgress:(float)progress animated:(BOOL)animated { - if (self.progress == progress) { + if (fequal(self.progress, progress)) { return; } diff --git a/README.md b/README.md index 65f1deb..ddf765c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Overview
The JGProgressHUD Tests example project contains all kinds of different uses of JGProgressHUD. Check out the code and see how much JGProgressHUD can do!
-#####Current Version: 1.2 +#####Current Version: 1.2.1 ##Customization: