UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入个人信息" preferredStyle:UIAlertControllerStyleAlert];
//增加确定按钮;
[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//获取第1个输入框;
UITextField *userNameTextField = alertController.textFields.firstObject;
//获取第2个输入框;
UITextField *passwordTextField = alertController.textFields.lastObject;
NSLog(@"用户名 = %@,密码 = %@",userNameTextField.text,passwordTextField.text);
}]];
//增加取消按钮;
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
//定义第一个输入框;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请输入用户名";
}];
//定义第二个输入框;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请输入密码";
}];
[self presentViewController:alertController animated:true completion:nil];
摘自:https://blog.csdn.net/chenyufeng1991/article/details/49537053