JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//
//  Copyright © 2018 Jimmy. All rights reserved.
//
//  封装UIAlertController,使用扩展的话太奇怪了
 
#import <UIKit/UIKit.h>
 
@class DHAlertController;
/// index为0表示取消,index为1表示其他按钮,index为100表示不再提示按钮
typedef void (^DHAlertControllerHandler)(NSInteger index);
 
@interface DHAlertController : UIAlertController
 
/**
 弹出框
 
 @param title 标题
 @param message 内容
 @param cancelButtonTitle 取消按钮
 @param otherButtonTitle 确定按钮
 @param handler 点击回调
 */
+ (DHAlertController *)showWithTitle:(NSString *)title
                             message:(NSString *)message
                   cancelButtonTitle:(NSString *)cancelButtonTitle
                    otherButtonTitle:(NSString *)otherButtonTitle
                             handler:(DHAlertControllerHandler)handler;
 
/**
弹出带"不再提示"按钮框
 
@param title 标题
@param message 内容
@param cancelButtonTitle 取消按钮
@param otherButtonTitle 确定按钮
@param tipsButtonTitle  不再提示按钮文字
@param tipsButtonNormalImage 不再提示按钮未选中图片
@param tipsButtonSelectedImage 不再提示按选中图片
@param handler 点击回调
*/
+ (DHAlertController *)showWithTitle:(NSString *)title
                             message:(NSString *)message
                   cancelButtonTitle:(NSString *)cancelButtonTitle
                    otherButtonTitle:(NSString *)otherButtonTitle
                     tipsButtonTitle:(NSString *)tipsButtonTitle
               tipsButtonNormalImage:(NSString *)tipsButtonNormalImage
             tipsButtonSelectedImage:(NSString *)tipsButtonSelectedImage
                             handler:(DHAlertControllerHandler)handler;
 
/**
 弹出警告框
 
 @param title 标题
 @param message 内容
 @param cancelButtonTitle 取消按钮
 @param otherButtonTitles 其它按钮数组
 @param handler handler
 
 注意: 该方法不能在已经是 present 出来的控制器中弹出警告框,请使用另外一个带控制器参数的方法弹出
 */
+ (DHAlertController *)showWithTitle:(NSString *)title
                             message:(NSString *)message
                   cancelButtonTitle:(NSString *)cancelButtonTitle
                   otherButtonTitles:(NSArray<NSString *> *)otherButtonTitles
                             handler:(DHAlertControllerHandler)handler;
 
/**
弹出Sheet框
 
@param cancelButtonTitle 取消按钮
@param otherButtonTitles 其他按钮
@param handler 点击回调
*/
+ (DHAlertController *)showSheetWithCancelButtonTitle:(NSString *)cancelButtonTitle
                                    otherButtonTitles:(NSArray <NSString *> *)otherButtonTitles
                                              handler:(DHAlertControllerHandler)handler;
 
/**
弹出带标题的Sheet框
 
@param title 标题
@param message 内容
@param cancelButtonTitle 取消按钮
@param otherButtonTitle 其他按钮
@param handler 点击回调
*/
+ (DHAlertController *)showSheetWithTitle:(NSString *)title
                                  message:(NSString *)message
                        cancelButtonTitle:(NSString *)cancelButtonTitle
                         otherButtonTitle:(NSString *)otherButtonTitle
                                  handler:(DHAlertControllerHandler)handler;
 
/**
弹出视图警告框
 
@param title 标题
@param customView 自定义视图
@param buttonTitle 按钮文字
@param handler handler
*/
+ (DHAlertController *)showWithTitle:(NSString *)title
                             message:(NSString *)message
                         buttonTitle:(NSString *)cancelButtonTitle
                             handler:(DHAlertControllerHandler)handler;
/**
弹出自定义视图警告框
 
@param title 标题
@param customView 自定义视图
@param cancelButtonTitle 取消按钮
@param otherButtonTitles 其它按钮数组
@param handler handler
 
注意: 该方法不能在已经是 present 出来的控制器中弹出警告框,请使用另外一个带控制器参数的方法弹出
*/
+ (DHAlertController *)showWithTitle:(NSString *)title
                          customView:(UIView *)customView
                   cancelButtonTitle:(NSString *)cancelButtonTitle
                    otherButtonTitle:(NSString *)otherButtonTitle
                             handler:(DHAlertControllerHandler)handler;
 
/**
 弹出框
 
 @param vc 需要显示在哪个控制器
 @param title 标题
 @param message 内容
 @param cancelButtonTitle 取消按钮
 @param otherButtonTitle 确定按钮
 @param handler 点击回调
 */
+ (DHAlertController *)showInViewController:(UIViewController *)vc
                                      title:(NSString *)title
                                    message:(NSString *)message
                          cancelButtonTitle:(NSString *)cancelButtonTitle
                           otherButtonTitle:(NSString *)otherButtonTitle
                                    handler:(DHAlertControllerHandler)handler;
 
/**
 根据指定vc弹出警告框
 
 @param vc 对应控制器
 @param title 标题
 @param message 内容
 @param cancelButtonTitle 取消按钮
 @param otherButtonTitles 其它按钮数组
 @param handler handler
 */
 
+ (DHAlertController *)showInViewController:(UIViewController *)vc
                                      title:(NSString *)title
                                    message:(NSString *)message
                          cancelButtonTitle:(NSString *)cancelButtonTitle
                          otherButtonTitles:(NSArray<NSString *> *)otherButtonTitles
                                    handler:(DHAlertControllerHandler)handler;
 
/**
弹出自定义视图警告框
 
@param title 标题
@param customView 自定义视图
@param cancelButtonTitle 取消按钮
@param otherButtonTitles 其它按钮数组
@param handler handler
*/
+ (DHAlertController *)showInViewController:(UIViewController *)vc
                                      title:(NSString *)title
                                 customView:(UIView *)customView
                          cancelButtonTitle:(NSString *)cancelButtonTitle
                           otherButtonTitle:(NSString *)otherButtonTitle
                                    handler:(DHAlertControllerHandler)handler;
 
/**
 隐藏弹出框
 
 @param isAnimated 是否动画
 */
+ (void)dismissAnimated:(BOOL)isAnimated;
 
/**
 隐藏弹出框,无动画
 */
+ (void)dismiss;
 
/**
 显示中
 */
+ (BOOL)isDisplayed;
 
/**
 找到最上层的弹出框,非UIAlertController
 
 @return UIViewController
 */
+ (UIViewController *)topPresentOrRootController;
 
@end