// 参数preferredStyle:是IAlertController的样式 // UIAlertControllerStyleAlert 建立出来至关于UIAlertView // UIAlertControllerStyleActionSheet 建立出来至关于 UIActionSheet UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"大标题(正文)" message:@"小标题(副文)" preferredStyle:UIAlertControllerStyleAlert]; // 建立按钮 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"肯定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { NSLog(@"注意学习"); }]; // 建立按钮 // 注意取消按钮只能添加一个 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { // 点击按钮后的方法直接在这里面写 NSLog(@"注意学习"); }]; // 建立警告按钮 UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) { NSLog(@"注意学习"); }]; // 添加按钮 将按钮添加到UIAlertController对象上 [alert addAction:okAction]; [alert addAction:cancelAction]; [alert addAction:structlAction]; // 只有在UIAlertControllerStyleAlert样式状况下才能够添加文本框,UIAlertControllerStyleActionSheet样式不支持文本框,会崩溃。 [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"用户名"; textField.secureTextEntry = YES; }]; // // 取出文本 // UITextField *text = alertController.textFields.firstObject; // UIAlertAction *action = alertController.actions.firstObject; // 将UIAlertController模态出来 至关于UIAlertView show 的方法 [self presentViewController:alert animated:YES completion:nil];