Created
April 4, 2017 11:15
-
-
Save randhirraj3130/3f4c6c3ea31e9ef0fecf9b618993ecca to your computer and use it in GitHub Desktop.
my custom alertview controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add text field in alert view controller | |
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Login" | |
message: @"Input username and password" | |
preferredStyle:UIAlertControllerStyleAlert]; | |
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { | |
textField.placeholder = @"name"; | |
textField.textColor = [UIColor blueColor]; | |
textField.clearButtonMode = UITextFieldViewModeWhileEditing; | |
textField.borderStyle = UITextBorderStyleRoundedRect; | |
}]; | |
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { | |
textField.placeholder = @"password"; | |
textField.textColor = [UIColor blueColor]; | |
textField.clearButtonMode = UITextFieldViewModeWhileEditing; | |
textField.borderStyle = UITextBorderStyleRoundedRect; | |
textField.secureTextEntry = YES; | |
}]; | |
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { | |
NSArray * textfields = alertController.textFields; | |
UITextField * namefield = textfields[0]; | |
UITextField * passwordfiled = textfields[1]; | |
NSLog(@"%@:%@",namefield.text,passwordfiled.text); | |
}]]; | |
[self presentViewController:alertController animated:YES completion:nil]; | |
// add text field in alert view controller | |
UIAlertController * alert= [UIAlertController | |
alertControllerWithTitle:@"H&L" | |
message:@"No match was found for this image! Do you want to try again?" | |
preferredStyle:UIAlertControllerStyleAlert]; | |
UIAlertAction* ok = [UIAlertAction | |
actionWithTitle:@"Retry" | |
style:UIAlertActionStyleDefault | |
handler:^(UIAlertAction * action) | |
{ | |
//[MyTabBarController] | |
[[self navigationController]popViewControllerAnimated:YES]; | |
[alert dismissViewControllerAnimated:YES completion:nil]; | |
}]; | |
UIAlertAction* cancel = [UIAlertAction | |
actionWithTitle:@"Cancel" | |
style:UIAlertActionStyleDefault | |
handler:^(UIAlertAction * action) | |
{ | |
[[self navigationController]popViewControllerAnimated:YES]; | |
self.navigationController.tabBarController.selectedIndex = 0; | |
NSLog(@"Resolving UIAlertActionController for tapping cancel button"); | |
[alert dismissViewControllerAnimated:YES completion:nil]; | |
}]; | |
[alert addAction:ok]; | |
[alert addAction:cancel]; | |
[self presentViewController:alert animated:YES completion:nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment