1111@class QMUIModalPresentationViewController;
1212@class QMUIButton;
1313@class QMUITextField;
14+ @class QMUIAlertController;
15+
1416
1517typedef NS_ENUM (NSInteger , QMUIAlertActionStyle) {
1618 QMUIAlertActionStyleDefault = 0 ,
@@ -23,117 +25,209 @@ typedef NS_ENUM(NSInteger, QMUIAlertControllerStyle) {
2325 QMUIAlertControllerStyleAlert
2426};
2527
28+
29+ @protocol QMUIAlertControllerDelegate <NSObject >
30+
31+ - (void )willShowAlertController : (QMUIAlertController *)alertController ;
32+ - (void )willHideAlertController : (QMUIAlertController *)alertController ;
33+ - (void )didShowAlertController : (QMUIAlertController *)alertController ;
34+ - (void )didHideAlertController : (QMUIAlertController *)alertController ;
35+
36+ @end
37+
38+
2639/* *
27- * QMUIAlertController的按钮,先初始化一个按钮再加到Controller上面即可
40+ * QMUIAlertController的按钮,初始化完通过`QMUIAlertController`的`addAction:`方法添加到 AlertController 上即可。
2841 */
2942@interface QMUIAlertAction : NSObject
3043
3144/* *
32- * 初始化QMUIAlertController的按钮
45+ * 初始化`QMUIAlertController`的按钮
3346 *
3447 * @param title 按钮标题
35- * @param style 按钮style,跟系统一样,有Default 、Cancel、Destructive三种类型
48+ * @param style 按钮style,跟系统一样,有 Default 、Cancel、Destructive 三种类型
3649 * @param handler 处理点击时间的block
3750 *
3851 * @return QMUIAlertController按钮的实例
3952 */
4053+ (instancetype )actionWithTitle : (NSString *)title style : (QMUIAlertActionStyle)style handler : (void (^)(QMUIAlertAction *action))handler ;
4154
55+ // / `QMUIAlertAction`对应的 button 对象
4256@property (nonatomic , strong , readonly ) QMUIButton *button;
43- @property (nonatomic , copy , readonly ) NSString *title;
44- @property (nonatomic , assign , readonly ) QMUIAlertActionStyle style;
45- @property (nonatomic , assign , getter =isEnabled) BOOL enabled;
4657
47- @end
58+ // / `QMUIAlertAction`对应的标题
59+ @property (nonatomic , copy , readonly ) NSString *title;
4860
61+ // / `QMUIAlertAction`对应的样式
62+ @property (nonatomic , assign , readonly ) QMUIAlertActionStyle style;
4963
50- @class QMUIAlertController;
64+ // / `QMUIAlertAction`是否允许操作
65+ @property (nonatomic , assign , getter =isEnabled) BOOL enabled;
5166
52- @protocol QMUIAlertControllerDelegate <NSObject >
67+ // / `QMUIAlertAction`按钮样式,默认nil。当此值为nil的时候,则使用`QMUIAlertController`的`alertButtonAttributes`或者`sheetButtonAttributes`的值。
68+ @property (nonatomic , strong ) NSDictionary <NSString *, id> *buttonAttributes;
5369
54- - (void )willShowAlertController : (QMUIAlertController *)alertController ;
55- - (void )willHideAlertController : (QMUIAlertController *)alertController ;
56- - (void )didShowAlertController : (QMUIAlertController *)alertController ;
57- - (void )didHideAlertController : (QMUIAlertController *)alertController ;
70+ // / 原理同上`buttonAttributes`
71+ @property (nonatomic , strong ) NSDictionary <NSString *, id> *buttonDisabledAttributes;
5872
5973@end
6074
6175
6276/* *
63- * QMUIAlertController是模仿系统UIAlertController的控件 ,所以系统有的功能在QMUIAlertController里面基本都有。同时QMUIAlertController还提供了一些扩展功能 ,例如:它的每个button都是开放处理的 ,可以对默认的按钮进行二次处理(比如加一个图片);可以通过appearance在app启动的时候通过本控件支持的属性任意修改整个QMUIAlertController的主题样式 。
77+ * `QMUIAlertController`是模仿系统`UIAlertController`的控件 ,所以系统有的功能在QMUIAlertController里面基本都有。同时`QMUIAlertController`还提供了一些扩展功能 ,例如:它的每个 button 都是开放出来的 ,可以对默认的按钮进行二次处理(比如加一个图片);可以通过 appearance 在 app 启动的时候修改整个`QMUIAlertController`的主题样式 。
6478 */
6579@interface QMUIAlertController : UIViewController
6680
81+ // / alert距离屏幕四边的间距,默认UIEdgeInsetsMake(0, 0, 0, 0)。alert的宽度最终是通过屏幕宽度减去水平的 alertContentMargin 和 alertContentMaximumWidth 决定的。
6782@property (nonatomic , assign ) UIEdgeInsets alertContentMargin UI_APPEARANCE_SELECTOR;
83+
84+ // / alert的最大宽度,默认270。
6885@property (nonatomic , assign ) CGFloat alertContentMaximumWidth UI_APPEARANCE_SELECTOR;
86+
87+ // / alert上分隔线颜色,默认UIColorMake(211, 211, 219)。
6988@property (nonatomic , strong ) UIColor *alertSeperatorColor UI_APPEARANCE_SELECTOR;
89+
90+ // / alert标题样式,默认@{NSForegroundColorAttributeName:UIColorBlack,NSFontAttributeName:UIFontBoldMake(17),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
7091@property (nonatomic , strong ) NSDictionary <NSString *, id> *alertTitleAttributes UI_APPEARANCE_SELECTOR;
92+
93+ // / alert信息样式,默认@{NSForegroundColorAttributeName:UIColorBlack,NSFontAttributeName:UIFontMake(13),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
7194@property (nonatomic , strong ) NSDictionary <NSString *, id> *alertMessageAttributes UI_APPEARANCE_SELECTOR;
95+
96+ // / alert按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontMake(17),NSKernAttributeName:@(0)}
7297@property (nonatomic , strong ) NSDictionary <NSString *, id> *alertButtonAttributes UI_APPEARANCE_SELECTOR;
98+
99+ // / alert按钮disabled时的样式,默认@{NSForegroundColorAttributeName:UIColorMake(129, 129, 129),NSFontAttributeName:UIFontMake(17),NSKernAttributeName:@(0)}
73100@property (nonatomic , strong ) NSDictionary <NSString *, id> *alertButtonDisabledAttributes UI_APPEARANCE_SELECTOR;
101+
102+ // / alert cancel 按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontBoldMake(17),NSKernAttributeName:@(0)}
74103@property (nonatomic , strong ) NSDictionary <NSString *, id> *alertCancelButtonAttributes UI_APPEARANCE_SELECTOR;
104+
105+ // / alert destructive 按钮样式,默认@{NSForegroundColorAttributeName:UIColorRed,NSFontAttributeName:UIFontMake(17),NSKernAttributeName:@(0)}
75106@property (nonatomic , strong ) NSDictionary <NSString *, id> *alertDestructiveButtonAttributes UI_APPEARANCE_SELECTOR;
107+
108+ // / alert圆角大小,默认值是:IOS_VERSION >= 9.0 ? 13 : 6,以保持与系统默认样式一致
76109@property (nonatomic , assign ) CGFloat alertContentCornerRadius UI_APPEARANCE_SELECTOR;
110+
111+ // / alert按钮高度,默认44pt
77112@property (nonatomic , assign ) CGFloat alertButtonHeight UI_APPEARANCE_SELECTOR;
113+
114+ // / alert头部(非按钮部分)背景色,默认值是:(IOS_VERSION < 8.0) ? UIColorWhite : UIColorMakeWithRGBA(247, 247, 247, 1)
78115@property (nonatomic , strong ) UIColor *alertHeaderBackgroundColor UI_APPEARANCE_SELECTOR;
116+
117+ // / alert按钮背景色,默认值同`alertHeaderBackgroundColor`
79118@property (nonatomic , strong ) UIColor *alertButtonBackgroundColor UI_APPEARANCE_SELECTOR;
119+
120+ // / alert按钮高亮背景色,默认UIColorMake(232, 232, 232)
80121@property (nonatomic , strong ) UIColor *alertButtonHighlightBackgroundColor UI_APPEARANCE_SELECTOR;
81- @property (nonatomic , assign ) CGFloat alertTitleMessageSpacing UI_APPEARANCE_SELECTOR;
122+
123+ // / alert头部四边insets间距
82124@property (nonatomic , assign ) UIEdgeInsets alertHeaderInsets UI_APPEARANCE_SELECTOR;
83125
126+ // / alert头部title和message之间的间距,默认3pt
127+ @property (nonatomic , assign ) CGFloat alertTitleMessageSpacing UI_APPEARANCE_SELECTOR;
128+
129+
130+ // / sheet距离屏幕四边的间距,默认UIEdgeInsetsMake(10, 10, 10, 10)。
84131@property (nonatomic , assign ) UIEdgeInsets sheetContentMargin UI_APPEARANCE_SELECTOR;
132+
133+ // / sheet的最大宽度,默认值是5.5英寸的屏幕的宽度减去水平的 sheetContentMargin
85134@property (nonatomic , assign ) CGFloat sheetContentMaximumWidth UI_APPEARANCE_SELECTOR;
135+
136+ // / sheet分隔线颜色,默认UIColorMake(211, 211, 219)
86137@property (nonatomic , strong ) UIColor *sheetSeperatorColor UI_APPEARANCE_SELECTOR;
138+
139+ // / sheet标题样式,默认@{NSForegroundColorAttributeName:UIColorMake(143, 143, 143),NSFontAttributeName:UIFontBoldMake(13),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
87140@property (nonatomic , strong ) NSDictionary <NSString *, id> *sheetTitleAttributes UI_APPEARANCE_SELECTOR;
141+
142+ // / sheet信息样式,默认@{NSForegroundColorAttributeName:UIColorMake(143, 143, 143),NSFontAttributeName:UIFontMake(13),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
88143@property (nonatomic , strong ) NSDictionary <NSString *, id> *sheetMessageAttributes UI_APPEARANCE_SELECTOR;
144+
145+ // / sheet按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontMake(20),NSKernAttributeName:@(0)}
89146@property (nonatomic , strong ) NSDictionary <NSString *, id> *sheetButtonAttributes UI_APPEARANCE_SELECTOR;
147+
148+ // / sheet按钮disabled时的样式,默认@{NSForegroundColorAttributeName:UIColorMake(129, 129, 129),NSFontAttributeName:UIFontMake(20),NSKernAttributeName:@(0)}
90149@property (nonatomic , strong ) NSDictionary <NSString *, id> *sheetButtonDisabledAttributes UI_APPEARANCE_SELECTOR;
150+
151+ // / sheet cancel 按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontBoldMake(20),NSKernAttributeName:@(0)}
91152@property (nonatomic , strong ) NSDictionary <NSString *, id> *sheetCancelButtonAttributes UI_APPEARANCE_SELECTOR;
153+
154+ // / sheet destructive 按钮样式,默认@{NSForegroundColorAttributeName:UIColorRed,NSFontAttributeName:UIFontMake(20),NSKernAttributeName:@(0)}
92155@property (nonatomic , strong ) NSDictionary <NSString *, id> *sheetDestructiveButtonAttributes UI_APPEARANCE_SELECTOR;
156+
157+ // / sheet cancel 按钮距离其上面元素(按钮或者header)的间距,默认8pt
93158@property (nonatomic , assign ) CGFloat sheetCancelButtonMarginTop UI_APPEARANCE_SELECTOR;
159+
160+ // / sheet内容的圆角,默认值是:(IOS_VERSION >= 9.0 ? 13 : 6),以保持与系统默认样式一致
94161@property (nonatomic , assign ) CGFloat sheetContentCornerRadius UI_APPEARANCE_SELECTOR;
162+
163+ // / sheet按钮高度,默认值是:(IOS_VERSION >= 9.0 ? 57 : 44),以保持与系统默认样式一致
95164@property (nonatomic , assign ) CGFloat sheetButtonHeight UI_APPEARANCE_SELECTOR;
165+
166+ // / sheet头部(非按钮部分)背景色,默认值是:(IOS_VERSION < 8.0) ? UIColorWhite : UIColorMakeWithRGBA(247, 247, 247, 1)
96167@property (nonatomic , strong ) UIColor *sheetHeaderBackgroundColor UI_APPEARANCE_SELECTOR;
168+
169+ // / sheet按钮背景色,默认值同`sheetHeaderBackgroundColor`
97170@property (nonatomic , strong ) UIColor *sheetButtonBackgroundColor UI_APPEARANCE_SELECTOR;
171+
172+ // / sheet按钮高亮背景色,默认UIColorMake(232, 232, 232)
98173@property (nonatomic , strong ) UIColor *sheetButtonHighlightBackgroundColor UI_APPEARANCE_SELECTOR;
99- @property (nonatomic , assign ) CGFloat sheetTitleMessageSpacing UI_APPEARANCE_SELECTOR;
174+
175+ // / sheet头部四边insets间距
100176@property (nonatomic , assign ) UIEdgeInsets sheetHeaderInsets UI_APPEARANCE_SELECTOR;
101177
178+ // / sheet头部title和message之间的间距,默认8pt
179+ @property (nonatomic , assign ) CGFloat sheetTitleMessageSpacing UI_APPEARANCE_SELECTOR;
102180
103181
104182// / 默认初始化方法
105183- (instancetype )initWithTitle : (NSString *)title message : (NSString *)message preferredStyle : (QMUIAlertControllerStyle)preferredStyle ;
106184
107- // / 通过类方法初始化
185+ // / 通过类方法初始化实例
108186+ (instancetype )alertControllerWithTitle : (NSString *)title message : (NSString *)message preferredStyle : (QMUIAlertControllerStyle)preferredStyle ;
109187
188+ // / @see `QMUIAlertControllerDelegate`
110189@property (nonatomic ,weak ) id <QMUIAlertControllerDelegate>delegate;
111190
112191// / 增加一个按钮
113192- (void )addAction : (QMUIAlertAction *)action ;
193+
114194// / 增加一个输入框
115195- (void )addTextFieldWithConfigurationHandler : (void (^)(UITextField *textField))configurationHandler ;
116- // / 增加一个自定义的view作为QMUIAlertController的contentView
196+
197+ // / 增加一个自定义的view作为`QMUIAlertController`的customView
117198- (void )addCustomView : (UIView *)view ;
118199
200+ // / 显示`QMUIAlertController`
119201- (void )showWithAnimated : (BOOL )animated ;
202+
203+ // / 隐藏`QMUIAlertController`
120204- (void )hideWithAnimated : (BOOL )animated ;
121205
206+ // / 所有`QMUIAlertAction`对象
122207@property (nonatomic , copy , readonly ) NSArray <QMUIAlertAction *> *actions;
208+
209+ // / 当前所有通过`addTextFieldWithConfigurationHandler:`接口添加的输入框
123210@property (nonatomic , copy , readonly ) NSArray <QMUITextField *> *textFields;
124- @property (nonatomic , strong , readonly ) UIView *customView;
125211
212+ // / 设置自定义view。通过`addCustomView:`方法添加一个自定义的view,`QMUIAlertController`会在布局的时候去掉用这个view的`sizeThatFits:`方法来获取size,至于x和y坐标则由控件自己控制。
213+ @property (nonatomic , strong , readonly ) UIView *customView;
214+
215+ // / 当前标题title
126216@property (nonatomic , copy ) NSString *title;
217+
218+ // / 当前信息message
127219@property (nonatomic , copy ) NSString *message;
220+
221+ // / 当前样式style
128222@property (nonatomic , assign , readonly ) QMUIAlertControllerStyle preferredStyle;
129223
130- // / 将QMUIAlert弹起来的工具Controller
224+ // / 将`QMUIAlertController`弹出来的`QMUIModalPresentationViewController`对象
131225@property (nonatomic , strong , readonly ) QMUIModalPresentationViewController *modalPresentationViewController;
132226
133227/* *
134- * 设置按钮的排序是否要由用户添加的顺序来决定,默认为NO,也即与系统原生UIAlertController一致,QMUIAlertActionStyleDestructive类型的action必定在最后面 。
228+ * 设置按钮的排序是否要由用户添加的顺序来决定,默认为NO,也即与系统原生`UIAlertController`一致,QMUIAlertActionStyleDestructive 类型的action必定在最后面 。
135229 *
136- * @warning 注意QMUIAlertActionStyleCancel按钮不受这个属性的影响
230+ * @warning 注意 QMUIAlertActionStyleCancel 按钮不受这个属性的影响
137231 */
138232@property (nonatomic , assign ) BOOL orderActionsByAddedOrdered;
139233
@@ -152,8 +246,7 @@ typedef NS_ENUM(NSInteger, QMUIAlertControllerStyle) {
152246
153247@interface QMUIAlertController (Manager)
154248
155- /* *
156- * 可方便地判断是否有alertController正在显示,全局生效
157- */
249+ // / 可方便地判断是否有 alertController 正在显示,全局生效
158250+ (BOOL )isAnyAlertControllerVisible ;
251+
159252@end
0 commit comments