티스토리 뷰
http://hayageek.com/uialertcontroller-example-ios/
//Create UIAlertController + (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler; //Adding an action - (void)addAction:(UIAlertAction *)action; //Adding text filed to UIAlertController.This method is supported only for UIAlertControllerStyleAlert - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler; UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"My Title" message:@"Enter User Credentials" preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:alert animated:YES completion:nil]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { //Do some thing here [view dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; // add action to uialertcontroller UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"Info" message:@"You are using UIAlertController" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; [alert addAction:cancel]; [self presentViewController:alert animated:YES completion:nil]; --------------------------- UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"Info" message:@"You are using UIAlertController" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; [alert addAction:cancel]; [self presentViewController:alert animated:YES completion:nil]; ------------------------ [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"Password"; //for passwords textField.secureTextEntry = YES; }]; ----------------------- UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"My Title" message:@"Enter User Credentials" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { //Do Some action here }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; [alert addAction:ok]; [alert addAction:cancel]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"Username"; }]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"Password"; textField.secureTextEntry = YES; }]; [self presentViewController:alert animated:YES completion:nil]; /
'Apple > Classes' 카테고리의 다른 글
NSOperation Code Examples (0) | 2017.07.27 |
---|---|
NSDate Code Examples (0) | 2017.07.23 |
NSURLSession Code Examples (0) | 2017.06.20 |
NSTimer Code Examples (0) | 2017.06.17 |
NSDictionary Code Examples (0) | 2017.06.12 |