-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomAlertViewController.m
167 lines (118 loc) · 5.58 KB
/
CustomAlertViewController.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// CustomAlertViewController.m
// MapShot
//
//
#import "CustomAlertViewController.h"
@interface CustomAlertViewController ()
@end
@implementation CustomAlertViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
newuserTextField= [[UITextField alloc] initWithFrame:CGRectMake(30, 70, 240, 40)];
newuserTextField.autocapitalizationType=UITextAutocapitalizationTypeNone;
newuserTextField.autocorrectionType=UITextAutocorrectionTypeNo;
newuserTextField.spellCheckingType=UITextSpellCheckingTypeNo;
newuserTextField.delegate = self;
newuserTextField.backgroundColor=[UIColor orangeColor];
newuserTextField.textColor=[UIColor whiteColor];
[contentView addSubview:newuserTextField];
checkMarkButton=[UIButton buttonWithType:UIButtonTypeCustom];
checkMarkButton.frame=CGRectMake(30, 125, 25, 25);
checkMarkButton.tag=555;
[checkMarkButton setImage:[UIImage imageNamed:@"checkUnselected.png"] forState:UIControlStateNormal];
[checkMarkButton addTarget:self action:@selector(checkMarkActionMethod:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:checkMarkButton];
agreeButton=[UIButton buttonWithType:UIButtonTypeCustom];
agreeButton.frame=CGRectMake(70, 115, 220, 25);
[agreeButton addTarget:self action:@selector(termsAndCondition:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:agreeButton];
agreeLabel=[[UILabel alloc] initWithFrame:CGRectMake(70, 120, 220, 25)];
agreeLabel.text=@"I agree to Terms and Conditions";
agreeLabel.backgroundColor=[UIColor clearColor];
agreeLabel.textColor=[UIColor whiteColor];
agreeLabel.font=[UIFont fontWithName:@"Helvetica" size:14];
[contentView addSubview:agreeLabel];
linkLabel=[[UILabel alloc] initWithFrame:CGRectMake(70, 145, 200, 2)];
linkLabel.backgroundColor=[UIColor whiteColor];
[contentView addSubview:linkLabel];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void) viewWillAppear:(BOOL)animated{
[newuserTextField becomeFirstResponder];
[super viewWillAppear:YES];
}
-(void) checkMarkActionMethod:(UIButton*)sender{
if (sender.tag==555){
checkMarkButton.tag=666;
[checkMarkButton setImage:[UIImage imageNamed:@"checkSelected.png"] forState:UIControlStateNormal];
}
else if (sender.tag==666){
checkMarkButton.tag=555;
[checkMarkButton setImage:[UIImage imageNamed:@"checkUnselected.png"] forState:UIControlStateNormal];
}
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)termsAndCondition:(UIButton*)sender{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
TermsAndConditonsViewController *termsObject =[storyBoard instantiateViewControllerWithIdentifier:@"termAndConditionId"];
[self.navigationController pushViewController:termsObject animated:YES];
}
-(IBAction) okAction:(UIButton*) sender{
if([newuserTextField.text length] == 0) {
UIAlertView *fillNameAlert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Please Choose Your New Name ." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[fillNameAlert show];
}
else {
if (checkMarkButton.tag==666){
[newuserTextField resignFirstResponder];
id<CustomAlertViewControllerDelegate> strongDelegate = self.delegate;
// Our delegate method is optional, so we should
// check that the delegate implements it
if ([strongDelegate respondsToSelector:@selector(customalertOK:button:textFieldValue:)]) {
[strongDelegate customalertOK:self button:sender textFieldValue:newuserTextField.text];
}
}
else if (checkMarkButton.tag==555){
UIAlertView *agreeTermsAndCondition=[[UIAlertView alloc] initWithTitle:@"Agree" message:@"Agree to the terms and condition of mapshot" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
agreeTermsAndCondition.tag=101;
[agreeTermsAndCondition show];
}
}
}
-(IBAction) cancelAction:(UIButton*) sender{
[newuserTextField resignFirstResponder];
id<CustomAlertViewControllerDelegate> strongDelegate = self.delegate;
// Our delegate method is optional, so we should
// check that the delegate implements it
if ([strongDelegate respondsToSelector:@selector(customalertCancel:button:)]) {
[strongDelegate customalertCancel:self button:sender];
}
}
#pragma mark - Keyboard Notification Methods
- (void)keyboardWasShown:(NSNotification *)notification
{
}
- (void) keyboardWillHide:(NSNotification *)notification {
}
@end