1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// IBTLoadingView.m
// XFFruit
//
// Created by Xummer on 3/30/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTLoadingView.h"
@implementation IBTLoadingView
#pragma mark - Class Methods
+ (void)showTips:(id)tips {
if ([tips isKindOfClass:[NSError class]]) {
[[self class] showHUDMessage:((NSError *)tips).localizedDescription];
}
else if ([tips isKindOfClass:[NSString class]]) {
[[self class] showHUDMessage:tips];
}
}
+ (void)showHUDMessage:(NSString *)message {
[IBTCommon runOnMainThreadWithoutDeadlocking:^{
[[self class] showTextOnly:message];
}];
}
+ (IBTLoadingView *)showHUDWithText:(NSString *)text
inView:(UIView *)view {
IBTLoadingView *hud = [IBTLoadingView showHUDAddedTo:view animated:YES];
if ([text length] < 20) {
hud.labelText = text;
}
else {
hud.detailsLabelText = text;
}
hud.removeFromSuperViewOnHide = YES;
return hud;
}
+ (void)showTextOnly:(NSString *)text inView:(UIView *)view {
IBTLoadingView *hud = [[self class] showHUDWithText:text inView:view];
hud.mode = MBProgressHUDModeText;
hud.margin = 10.0f;
// hud.yOffset = 0.f;
[hud hide:YES afterDelay:1];
}
+ (void)showTextOnly:(NSString *)text {
IBTLoadingView *hud = [[self class] showHUDWithText:text inView:[[self class] hudShowWindow]];
hud.mode = MBProgressHUDModeText;
hud.margin = 10.0f;
hud.yOffset = 60.0f;
[hud hide:YES afterDelay:4];
}
+ (void)showProgressLabel:(NSString *)text {
IBTLoadingView *hud = [[self class] showHUDWithText:text inView:[[self class] hudShowWindow]];
hud.mode = MBProgressHUDModeIndeterminate;
}
+ (void)hideHUDWithText:(NSString *)text {
[[self class] hideHUDForView:[[self class] hudShowWindow] withText:text];
}
+ (void)showProgressLabel:(NSString *)text
inView:(UIView *)view {
IBTLoadingView *hud = [[self class] showHUDWithText:text inView:view];
hud.mode = MBProgressHUDModeIndeterminate;
}
+ (void)showCustomView:(UIView *)customview
inView:(UIView *)view {
IBTLoadingView *hud = [[IBTLoadingView alloc] initWithView:view];
hud.customView = customview;
// Set custom view mode
hud.mode = MBProgressHUDModeCustomView;
[hud show:YES];
}
+ (void)hideHUDForView:(UIView *)view {
[IBTCommon runOnMainThreadWithoutDeadlocking:^{
[IBTLoadingView hideHUDForView:view animated:YES];
}];
}
+ (void)hideHUDForView:(UIView *)view
withText:(NSString *)text {
[IBTLoadingView hideHUDForView:view animated:YES];
if ([text isKindOfClass:[NSString class]]) {
if (text.length > 0) {
[[self class] showTextOnly:text];
}
}
}
+ (UIWindow *)hudShowWindow {
UIWindow *showWindow = nil;
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] >= 2) {
showWindow = [windows objectAtIndex:1];
}
else {
showWindow = [[UIApplication sharedApplication] keyWindow];
}
return showWindow;
}
@end