Skip to content

Commit a22f5d0

Browse files
author
YSC
committed
Update->Add custom HUD method / Add BigGry & small white indicator style
1 parent d7f3003 commit a22f5d0

File tree

3 files changed

+107
-18
lines changed

3 files changed

+107
-18
lines changed

Demo/WSProgressHUD/WSProgressHUD.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ typedef NS_ENUM(NSInteger, WSProgressHUDIndicatorStyle) {
2626
WSProgressHUDIndicatorCustom,
2727
WSProgressHUDIndicatorMMSpinner,
2828
WSProgressHUDIndicatorSmallLight,
29+
WSProgressHUDIndicatorGray,
30+
WSProgressHUDIndicatorBigGray,//Avaliable ios 7.0+
2931
};
3032

3133

@@ -67,7 +69,7 @@ typedef NS_ENUM(NSInteger, WSProgressHUDIndicatorStyle) {
6769
/*----------------------------Custom---------------------------------*/
6870

6971
+ (void)setProgressHUDIndicatorStyle: (WSProgressHUDIndicatorStyle)style;
70-
72+
+ (void)setProgressHUDFont: (UIFont *)font;
7173

7274
/*----------------------Show On the view------------------------------*/
7375

@@ -98,7 +100,11 @@ typedef NS_ENUM(NSInteger, WSProgressHUDIndicatorStyle) {
98100
- (void)showSuccessWithString: (NSString *)string;
99101
- (void)showErrorWithString: (NSString *)string;
100102

101-
102103
- (void)dismiss;
103104

105+
/*----------------------------Custom---------------------------------*/
106+
- (void)setProgressHUDIndicatorStyle: (WSProgressHUDIndicatorStyle)style;
107+
- (void)setProgressHUDFont: (UIFont *)font;
108+
109+
104110
@end

Demo/WSProgressHUD/WSProgressHUD.m

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ @interface WSProgressHUD ()
5252

5353
@property (nonatomic) BOOL isRotate;
5454

55-
@property (nonatomic) UIInterfaceOrientation currentDeviceOrientation;
56-
55+
@property (nonatomic) BOOL isTempIndicatorStyle;
5756

5857
@end
5958

@@ -85,7 +84,7 @@ @interface WSProgressHUD ()
8584
static CGFloat WSProgressHUDDismissDuration = 0.15;
8685
static CGFloat const WSProgressHUDWidthEdgeOffset = 10;
8786
static CGFloat const WSProgressHUDHeightEdgeOffset = 8;
88-
static CGFloat const WSProgressHUDImageTypeWidthEdgeOffset = 30;
87+
static CGFloat const WSProgressHUDImageTypeWidthEdgeOffset = 16;
8988

9089

9190
@implementation WSProgressHUD
@@ -477,9 +476,15 @@ - (void)dismiss
477476
self.hudView.transform = CGAffineTransformIdentity;
478477

479478
[self.overlayView removeFromSuperview];
479+
480480
self.userInteractionEnabled = NO;
481+
481482
[self stopIndicatorAnimation];
483+
484+
//Call drawInRact
482485
[self setNeedsDisplay];
486+
487+
[self setProgressHUDIndicatorStyle:self.indicatorStyle];
483488
}];
484489
}
485490

@@ -537,8 +542,6 @@ - (void)updateSubviewsPosition
537542
} else {
538543
[self updatePositionWithString:string hudBounds:hudBounds];
539544
}
540-
541-
542545
}
543546

544547
- (void)updatePositionWithString: (NSString *)string hudBounds: (CGRect)bounds
@@ -549,6 +552,7 @@ - (void)updatePositionWithString: (NSString *)string hudBounds: (CGRect)bounds
549552
self.hudView.bounds = bounds;
550553
self.labelView.frame = WSProgressHUDStringRect;//Reset the view frame
551554
self.hudView.center = CGPointMake(centerX, centerY);
555+
self.hudView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
552556

553557
CGFloat hudCenterX = CGRectGetWidth(bounds)/2;
554558
CGFloat hudCenterY = CGRectGetHeight(bounds)/2;
@@ -559,11 +563,28 @@ - (void)updatePositionWithString: (NSString *)string hudBounds: (CGRect)bounds
559563
[self startIndicatorAnimation:YES];
560564

561565
if (string) {
566+
567+
if (self.indicatorStyle == WSProgressHUDIndicatorGray ||
568+
self.indicatorStyle == WSProgressHUDIndicatorBigGray) {
569+
570+
self.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
571+
}
572+
562573
self.labelView.frame = WSProgressHUDStringRect;
563574
self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY);
564575
self.spinnerView.center = self.indefiniteAnimationView.center = self.indicatorView.center = CGPointMake(15, hudCenterY);
565576

566577
} else {
578+
579+
if (self.indicatorStyle == WSProgressHUDIndicatorGray ||
580+
self.indicatorStyle == WSProgressHUDIndicatorBigGray ) {
581+
self.hudView.backgroundColor = [UIColor clearColor];
582+
if (self.maskType == WSProgressHUDMaskTypeBlack || self.maskType == WSProgressHUDMaskTypeGradient) {
583+
self.indicatorView.color = [UIColor whiteColor];
584+
} else {
585+
self.indicatorView.color = [UIColor grayColor];
586+
}
587+
}
567588
self.spinnerView.center = self.indefiniteAnimationView.center = self.indicatorView.center = CGPointMake(hudCenterX, hudCenterY);
568589
}
569590

@@ -856,6 +877,31 @@ - (void)startIndicatorAnimation: (BOOL)start
856877
self.spinnerView.hidden = YES;
857878
}
858879
}break;
880+
case WSProgressHUDIndicatorGray: {
881+
882+
self.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
883+
884+
self.indefiniteAnimationView.hidden = YES;
885+
self.spinnerView.hidden = YES;
886+
if (start) {
887+
[self.indicatorView startAnimating];
888+
} else {
889+
[self.indicatorView stopAnimating];
890+
}
891+
}break;
892+
case WSProgressHUDIndicatorBigGray: {
893+
894+
self.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
895+
self.indicatorView.color = [UIColor lightGrayColor];
896+
self.indefiniteAnimationView.hidden = YES;
897+
self.spinnerView.hidden = YES;
898+
if (start) {
899+
[self.indicatorView startAnimating];
900+
} else {
901+
[self.indicatorView stopAnimating];
902+
}
903+
}break;
904+
859905
default:
860906
break;
861907
}
@@ -1010,6 +1056,18 @@ + (void)setProgressHUDIndicatorStyle: (WSProgressHUDIndicatorStyle)style {
10101056
[[self shareInstance] setProgressHUDIndicatorStyle:style];
10111057
}
10121058

1059+
+ (void)setProgressHUDFont: (UIFont *)font
1060+
{
1061+
[[self shareInstance] setProgressHUDFont:font];
1062+
}
1063+
1064+
- (void)setProgressHUDFont: (UIFont *)font
1065+
{
1066+
self.labelView.font = self.shimmeringLabel.font = font;
1067+
}
1068+
1069+
1070+
10131071
- (void)setProgressHUDIndicatorStyle: (WSProgressHUDIndicatorStyle)style {
10141072
objc_setAssociatedObject(self, @selector(indicatorStyle), @(style), OBJC_ASSOCIATION_ASSIGN);
10151073
}

Demo/WSProgressHUDDemo/ViewController.m

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ - (void)viewDidLoad {
3636
[hud dismiss];
3737
});
3838

39+
[self registerOrientationDidChangeObserve];
3940
}
4041

4142
- (void)didReceiveMemoryWarning {
@@ -44,25 +45,23 @@ - (void)didReceiveMemoryWarning {
4445
}
4546
- (IBAction)show:(id)sender {
4647

47-
// [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorCustom];
48-
[WSProgressHUD showWithMaskType:WSProgressHUDMaskTypeBlack];
48+
[WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorGray];
49+
[WSProgressHUD show];
4950

50-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
51-
[WSProgressHUD dismiss];
52-
});
51+
[self autoDismiss];
5352
}
5453

5554
- (IBAction)showShimmeringString:(id)sender {
5655
// [hud show];
57-
[WSProgressHUD showShimmeringString:@"WSProgressHUD Loading..."];
56+
[WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
5857

59-
58+
// [WSProgressHUD showShimmeringString:@"WSProgressHUD Loading..." maskType:WSProgressHUDMaskTypeBlack maskWithout:WSProgressHUDMaskWithoutNavigation];
59+
[WSProgressHUD show];
60+
61+
[self autoDismiss];
6062
}
6163
- (IBAction)showWithString:(id)sender {
6264
[WSProgressHUD showWithStatus:@"Loading..." maskType:WSProgressHUDMaskTypeBlack maskWithout:WSProgressHUDMaskWithoutTabbar];
63-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
64-
[WSProgressHUD dismiss];
65-
});
6665

6766
}
6867
- (IBAction)showProgress:(id)sender {
@@ -84,7 +83,13 @@ - (void)increaseProgress {
8483

8584

8685
- (IBAction)showImage:(id)sender {
87-
[WSProgressHUD showSuccessWithStatus:@"I was not delivered unto this world in defeat, nor does failure course in my veins. I am not a sheep waiting to be prodded by my shepherd. I am a lion and I refuse to talk, to walk, to sleep with the sheep. I will hear not those who weep and complain, for their disease is contagious. Let them join the sheep. The slaughterhouse of failure is not my destiny."];
86+
87+
[WSProgressHUD showWithMaskType:WSProgressHUDMaskTypeBlack];
88+
[self autoDismiss];
89+
90+
// [WSProgressHUD setProgressHUDFont:[UIFont systemFontOfSize:18]];
91+
92+
// [WSProgressHUD showSuccessWithStatus:@"I was not delivered unto this world in defeat, nor does failure course in my veins. I am not a sheep waiting to be prodded by my shepherd. I am a lion and I refuse to talk, to walk, to sleep with the sheep. I will hear not those who weep and complain, for their disease is contagious. Let them join the sheep. The slaughterhouse of failure is not my destiny."];
8893

8994
}
9095
- (IBAction)showString:(id)sender {
@@ -95,4 +100,24 @@ - (IBAction)dismiss:(id)sender {
95100
[WSProgressHUD dismiss];
96101
}
97102

103+
104+
- (void)autoDismiss
105+
{
106+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
107+
[WSProgressHUD dismiss];
108+
});
109+
110+
}
111+
- (void)registerOrientationDidChangeObserve
112+
{
113+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
114+
115+
}
116+
117+
- (void)statusBarOrientationDidChange: (NSNotification *)notification {
118+
NSLog(@"%@", NSStringFromCGRect(self.navigationController.navigationBar.frame));
119+
}
120+
121+
122+
98123
@end

0 commit comments

Comments
 (0)