Skip to content

Commit 8d56e89

Browse files
author
Andria Jensen
committed
Made compatible with iOS 6. Added ability to set text and image color separately. Added ability to ignore the keyboard when setting the HUD view's offset
Signed-off-by: Andria Jensen <andria@logicalzen.com>
1 parent 573b9bc commit 8d56e89

3 files changed

Lines changed: 48 additions & 24 deletions

File tree

SVProgressHUD.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Pod::Spec.new do |s|
66
s.summary = 'A clean and lightweight progress HUD for your iOS app.'
77
s.homepage = 'http://samvermette.com/199'
88
s.author = { 'Sam Vermette' => 'hello@samvermette.com' }
9-
s.source = { :git => 'https://github.com/samvermette/SVProgressHUD.git', :tag => s.version.to_s }
9+
s.source = { :git => 'https://github.com/VIPAAR/SVProgressHUD.git', :tag => s.version.to_s }
1010

1111
s.description = 'SVProgressHUD is an easy-to-use, clean and lightweight progress HUD for iOS. It’s a simplified and prettified alternative to the popular MBProgressHUD. The success and error icons are from Glyphish.'
1212

SVProgressHUD/SVProgressHUD.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ typedef NSUInteger SVProgressHUDMaskType;
3232
#pragma mark - Customization
3333

3434
+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor]
35-
+ (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor]
35+
+ (void)setRingColor:(UIColor *)color;
36+
+ (void)setTextColor:(UIColor *)color;
3637
+ (void)setRingThickness:(CGFloat)width; // default is 4 pt
3738
+ (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
3839
+ (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Glyphish
@@ -56,6 +57,7 @@ typedef NSUInteger SVProgressHUDMaskType;
5657
+ (void)showErrorWithStatus:(NSString *)string;
5758
+ (void)showImage:(UIImage*)image status:(NSString*)status; // use 28x28 white pngs
5859

60+
+ (void)setOffsetFromCenter:(UIOffset)offset adjustForKeyboard:(BOOL)adjustForKeyboard;
5961
+ (void)setOffsetFromCenter:(UIOffset)offset;
6062
+ (void)resetOffsetFromCenter;
6163

SVProgressHUD/SVProgressHUD.m

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
NSString * const SVProgressHUDStatusUserInfoKey = @"SVProgressHUDStatusUserInfoKey";
2424

2525
static UIColor *SVProgressHUDBackgroundColor;
26-
static UIColor *SVProgressHUDForegroundColor;
26+
static UIColor *SVProgressHUDRingColor;
27+
static UIColor *SVProgressHUDTextColor;
2728
static CGFloat SVProgressHUDRingThickness;
2829
static UIFont *SVProgressHUDFont;
2930
static UIImage *SVProgressHUDSuccessImage;
3031
static UIImage *SVProgressHUDErrorImage;
32+
static BOOL SVProgressHUDAdjustOffsetForKeyboard;
3133

3234
static const CGFloat SVProgressHUDRingRadius = 18;
3335
static 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

Comments
 (0)