2323NSString * const SVProgressHUDStatusUserInfoKey = @" SVProgressHUDStatusUserInfoKey" ;
2424
2525static UIColor *SVProgressHUDBackgroundColor;
26- static UIColor *SVProgressHUDForegroundColor;
26+ static UIColor *SVProgressHUDRingColor;
27+ static UIColor *SVProgressHUDTextColor;
2728static CGFloat SVProgressHUDRingThickness;
2829static UIFont *SVProgressHUDFont;
2930static UIImage *SVProgressHUDSuccessImage;
3031static UIImage *SVProgressHUDErrorImage;
32+ static BOOL SVProgressHUDAdjustOffsetForKeyboard;
3133
3234static const CGFloat SVProgressHUDRingRadius = 18 ;
3335static const CGFloat SVProgressHUDRingNoTextRadius = 24 ;
@@ -94,9 +96,14 @@ + (void)setBackgroundColor:(UIColor *)color {
9496 SVProgressHUDBackgroundColor = color;
9597}
9698
97- + (void )setForegroundColor : (UIColor *)color {
99+ + (void )setRingColor : (UIColor *)color {
98100 [self sharedView ];
99- SVProgressHUDForegroundColor = color;
101+ SVProgressHUDRingColor = color;
102+ }
103+
104+ + (void )setTextColor : (UIColor *)color {
105+ [self sharedView ];
106+ SVProgressHUDTextColor = color;
100107}
101108
102109+ (void )setFont : (UIFont *)font {
@@ -184,6 +191,11 @@ + (void)dismiss {
184191
185192#pragma mark - Offset
186193
194+ + (void )setOffsetFromCenter : (UIOffset)offset adjustForKeyboard : (BOOL )adjustForKeyboard {
195+ SVProgressHUDAdjustOffsetForKeyboard = adjustForKeyboard;
196+ [self setOffsetFromCenter: offset];
197+ }
198+
187199+ (void )setOffsetFromCenter : (UIOffset)offset {
188200 [self sharedView ].offsetFromCenter = offset;
189201}
@@ -204,10 +216,11 @@ - (id)initWithFrame:(CGRect)frame {
204216 self.activityCount = 0 ;
205217
206218 SVProgressHUDBackgroundColor = [UIColor whiteColor ];
207- SVProgressHUDForegroundColor = [UIColor blackColor ];
208- SVProgressHUDFont = [UIFont preferredFontForTextStyle: UIFontTextStyleSubheadline];
209- SVProgressHUDSuccessImage = [[UIImage imageNamed: @" SVProgressHUD.bundle/success" ] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];
210- SVProgressHUDErrorImage = [[UIImage imageNamed: @" SVProgressHUD.bundle/error" ] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];
219+ SVProgressHUDTextColor = [UIColor blackColor ];
220+ SVProgressHUDRingColor = [UIColor blackColor ];
221+ // SVProgressHUDFont = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
222+ SVProgressHUDSuccessImage = [UIImage imageNamed: @" SVProgressHUD.bundle/success" ]; // imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
223+ SVProgressHUDErrorImage = [UIImage imageNamed: @" SVProgressHUD.bundle/error" ]; // imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
211224 SVProgressHUDRingThickness = 4 ;
212225 }
213226
@@ -258,15 +271,15 @@ - (void)updatePosition {
258271 CGFloat stringHeight = 0 ;
259272 CGRect labelRect = CGRectZero;
260273
261- NSString *string = self.stringLabel .text ;
274+ NSAttributedString *string = self.stringLabel .attributedText ;
262275 // False if it's text-only
263276 BOOL imageUsed = (self.imageView .image ) || (self.imageView .hidden );
264277
265278 if (string) {
266279 CGSize constraintSize = CGSizeMake (200 , 300 );
280+
267281 CGRect stringRect = [string boundingRectWithSize: constraintSize
268282 options: (NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin)
269- attributes: @{NSFontAttributeName : self.stringLabel .font }
270283 context: NULL ];
271284 stringWidth = stringRect.size .width ;
272285 stringHeight = ceil (stringRect.size .height );
@@ -366,8 +379,7 @@ - (void)registerNotifications {
366379}
367380
368381
369- - (NSDictionary *)notificationUserInfo
370- {
382+ - (NSDictionary *)notificationUserInfo {
371383 return (self.stringLabel .text ? @{SVProgressHUDStatusUserInfoKey : self.stringLabel .text } : nil );
372384}
373385
@@ -379,6 +391,7 @@ - (void)positionHUD:(NSNotification*)notification {
379391
380392 UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
381393
394+
382395 if (notification) {
383396 NSDictionary * keyboardInfo = [notification userInfo ];
384397 CGRect keyboardFrame = [[keyboardInfo valueForKey: UIKeyboardFrameBeginUserInfoKey] CGRectValue ];
@@ -391,10 +404,12 @@ - (void)positionHUD:(NSNotification*)notification {
391404 keyboardHeight = keyboardFrame.size .width ;
392405 } else
393406 keyboardHeight = 0 ;
407+
394408 } else {
395409 keyboardHeight = self.visibleKeyboardHeight ;
396410 }
397411
412+
398413 CGRect orientationFrame = [UIScreen mainScreen ].bounds ;
399414 CGRect statusBarFrame = [UIApplication sharedApplication ].statusBarFrame ;
400415
@@ -410,10 +425,13 @@ - (void)positionHUD:(NSNotification*)notification {
410425
411426 CGFloat activeHeight = orientationFrame.size .height ;
412427
413- if (keyboardHeight > 0 )
414- activeHeight += statusBarFrame.size .height *2 ;
428+ if (SVProgressHUDAdjustOffsetForKeyboard) {
429+ if (keyboardHeight > 0 ) {
430+ activeHeight += statusBarFrame.size .height *2 ;
431+ }
432+ activeHeight -= keyboardHeight;
433+ }
415434
416- activeHeight -= keyboardHeight;
417435 CGFloat posY = floor (activeHeight*0.45 );
418436 CGFloat posX = orientationFrame.size .width /2 ;
419437
@@ -564,7 +582,9 @@ - (void)showImage:(UIImage *)image status:(NSString *)string duration:(NSTimeInt
564582 if (![self .class isVisible ])
565583 [self .class show ];
566584
567- self.imageView .tintColor = SVProgressHUDForegroundColor;
585+ if ([self .imageView respondsToSelector: @selector (setTintColor: )]) {
586+ self.imageView .tintColor = SVProgressHUDRingColor;
587+ }
568588 self.imageView .image = image;
569589 self.imageView .hidden = NO ;
570590
@@ -658,7 +678,7 @@ - (CAShapeLayer*)indefiniteAnimatedLayer {
658678 _indefiniteAnimatedLayer.contentsScale = [[UIScreen mainScreen ] scale ];
659679 _indefiniteAnimatedLayer.frame = rect;
660680 _indefiniteAnimatedLayer.fillColor = [UIColor clearColor ].CGColor ;
661- _indefiniteAnimatedLayer.strokeColor = SVProgressHUDForegroundColor .CGColor ;
681+ _indefiniteAnimatedLayer.strokeColor = SVProgressHUDRingColor .CGColor ;
662682 _indefiniteAnimatedLayer.lineWidth = SVProgressHUDRingThickness;
663683 _indefiniteAnimatedLayer.lineCap = kCALineCapRound ;
664684 _indefiniteAnimatedLayer.lineJoin = kCALineJoinBevel ;
@@ -710,7 +730,7 @@ - (CAShapeLayer *)ringLayer {
710730 _ringLayer = [self createRingLayerWithCenter: center
711731 radius: SVProgressHUDRingRadius
712732 lineWidth: SVProgressHUDRingThickness
713- color: SVProgressHUDForegroundColor ];
733+ color: SVProgressHUDRingColor ];
714734 [self .hudView.layer addSublayer: _ringLayer];
715735 }
716736 return _ringLayer;
@@ -722,7 +742,7 @@ - (CAShapeLayer *)backgroundRingLayer {
722742 _backgroundRingLayer = [self createRingLayerWithCenter: center
723743 radius: SVProgressHUDRingRadius
724744 lineWidth: SVProgressHUDRingThickness
725- color: [SVProgressHUDForegroundColor colorWithAlphaComponent: 0.1 ]];
745+ color: [SVProgressHUDRingColor colorWithAlphaComponent: 0.1 ]];
726746 _backgroundRingLayer.strokeEnd = 1 ;
727747 [self .hudView.layer addSublayer: _backgroundRingLayer];
728748 }
@@ -809,8 +829,10 @@ - (UIView *)hudView {
809829 effectY.minimumRelativeValue = @(-SVProgressHUDParallaxDepthPoints);
810830 effectY.maximumRelativeValue = @(SVProgressHUDParallaxDepthPoints);
811831
812- [_hudView addMotionEffect: effectX];
813- [_hudView addMotionEffect: effectY];
832+ if ([_hudView respondsToSelector: @selector (addMotionEffect: )]) {
833+ [_hudView addMotionEffect: effectX];
834+ [_hudView addMotionEffect: effectY];
835+ }
814836
815837 [self addSubview: _hudView];
816838 }
@@ -824,7 +846,7 @@ - (UILabel *)stringLabel {
824846 _stringLabel.adjustsFontSizeToFitWidth = YES ;
825847 _stringLabel.textAlignment = NSTextAlignmentCenter;
826848 _stringLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
827- _stringLabel.textColor = SVProgressHUDForegroundColor ;
849+ _stringLabel.textColor = SVProgressHUDTextColor ;
828850 _stringLabel.font = SVProgressHUDFont;
829851 _stringLabel.numberOfLines = 0 ;
830852 }
@@ -837,7 +859,7 @@ - (UILabel *)stringLabel {
837859
838860- (UIImageView *)imageView {
839861 if (_imageView == nil )
840- _imageView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , 28 , 28 )];
862+ _imageView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , 40 , 40 )];
841863
842864 if (!_imageView.superview )
843865 [self .hudView addSubview: _imageView];
0 commit comments