-
Notifications
You must be signed in to change notification settings - Fork 0
/
SJAlert.m
executable file
·147 lines (125 loc) · 7.51 KB
/
SJAlert.m
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
//
// SJHelperClass.m
// GlobalProject
//
// Created by Saurabh on 08/07/16.
// Copyright © 2016 Aryavrat Infotech. All rights reserved.
//
#import "SJAlert.h"
@implementation SJAlert
+(void)showSimpleAlertWithTitle:(NSString *)title message:(NSString *)message actionTitle: (NSString *)actionTitle onController:(UIViewController *)controller{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action=[UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:nil];
[alert addAction:action];
[controller presentViewController:alert animated:YES completion:nil];
}
+(void)showSingleButtonAlertWithTitle: (NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle onColtroller:(UIViewController *)controller handler:(void(^)(BOOL))completionHander{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action=[UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(completionHander)
completionHander(YES);
}];
[alert addAction:action];
[controller presentViewController:alert animated:YES completion:nil];
}
+(void)showDoubleButtonAlertWithTitle:(NSString *)title message:(NSString *)message actionTitle1:(NSString *)actionTitle1 actionTitle2:(NSString *)actionTitle2 alertStyle:(UIAlertControllerStyle)style onController:(UIViewController *)controller handler1:(void(^)(BOOL success1))CompletionHandler1 handler2:(void(^)(BOOL success2))CompletionHandler2{
UIAlertController *alert= [UIAlertController alertControllerWithTitle:title message:message preferredStyle:style];
UIAlertAction *action1=[UIAlertAction actionWithTitle:actionTitle1 style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(CompletionHandler1)
CompletionHandler1(YES);
}];
UIAlertAction *action2= [UIAlertAction actionWithTitle:actionTitle2 style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(CompletionHandler2)
CompletionHandler2(YES);
}];
if(style==UIAlertControllerStyleActionSheet){
UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
}
[alert addAction:action1];
[alert addAction:action2];
[controller presentViewController:alert animated:YES completion:nil];
}
+(void)showSingleTextAlertWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle placeHolder:(NSString *)placeHolder onController:(UIViewController *)controller handler:(void (^)(UITextField *))CompletionHandler{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder=placeHolder;
}];
UIAlertAction *action=[UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UITextField *text=alert.textFields.firstObject;
if(CompletionHandler)
CompletionHandler(text);
}];
[alert addAction:action];
[controller presentViewController:alert animated:YES completion:nil];
}
+(void)showDoubleTextAlertWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle placeHolder1:(NSString *)placeHolder1 placeHolder2:(NSString *)placeHolder2 isPassword:(BOOL)password onController:(UIViewController *)controller handler:(void(^)(UITextField *text1,UITextField *text2))completionHandler{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder=placeHolder1;
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder=placeHolder2;
if(password)
textField.secureTextEntry=YES;
}];
UIAlertAction *action=[UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UITextField *text1= alert.textFields.firstObject;
UITextField *text2= alert.textFields.lastObject;
if(completionHandler)
completionHandler(text1,text2);
}];
[alert addAction:action];
[controller presentViewController:alert animated:YES completion:nil];
}
+(void)showAnimatableAlertWithMessage:(NSString *)message height:(CGFloat)height fontSize:(CGFloat)fontSize isUpDirection:(BOOL)direction backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor onController:(UIViewController *)controller handler:(void(^)(BOOL success))completionHander{
UIView *backgroundView= [[UIView alloc]initWithFrame:controller.view.frame];
backgroundView.backgroundColor= [UIColor lightGrayColor];
backgroundView.layer.opacity=0.3;
[controller.view addSubview:backgroundView];
if(direction){
backgroundView.hidden=YES;
UILabel *textLable=[[UILabel alloc]initWithFrame:CGRectMake(0, -height, controller.view.frame.size.width, height)];
textLable.text=message;
textLable.backgroundColor=backgroundColor;
textLable.textColor=textColor;
textLable.textAlignment=NSTextAlignmentCenter;
textLable.font=[UIFont boldSystemFontOfSize:fontSize];
[controller.view addSubview:textLable];
[UIView animateWithDuration:0.5 animations:^{
backgroundView.hidden=NO;
[textLable setFrame:CGRectMake(0, 0, controller.view.frame.size.width, textLable.frame.size.height)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 delay:2.0 options:kNilOptions animations:^{
[textLable setFrame:CGRectMake(0, -height, controller.view.frame.size.width, textLable.frame.size.height)];
} completion:^(BOOL finished){
backgroundView.hidden=YES;
if(completionHander)
completionHander(YES);
}];
}];
}
else{
backgroundView.hidden=YES;
UILabel *textLable=[[UILabel alloc]initWithFrame:CGRectMake(0, controller.view.frame.size.height, controller.view.frame.size.width, height)];
textLable.text=message;
textLable.backgroundColor=backgroundColor;
textLable.textColor=textColor;
textLable.textAlignment=NSTextAlignmentCenter;
textLable.font=[UIFont boldSystemFontOfSize:fontSize];
[controller.view addSubview:textLable];
[UIView animateWithDuration:0.5 animations:^{
backgroundView.hidden=NO;
[textLable setFrame:CGRectMake(0, controller.view.frame.size.height-height, controller.view.frame.size.width, textLable.frame.size.height)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 delay:2.0 options:kNilOptions animations:^{
[textLable setFrame:CGRectMake(0, controller.view.frame.size.height, controller.view.frame.size.width, textLable.frame.size.height)];
} completion:^(BOOL finished){
backgroundView.hidden=YES;
if(completionHander)
completionHander(YES);
}];
}];
}
}
@end