使用UIAlertController需要三步
1、实例化alert:alertControllerWithTitle
2、实例化按钮:actionWithTitle
3、显示alertController:presentViewController
下面是实现上面三步的简单代码
//实例化alert:alertControllerWithTitle
UIAlertController *alert= [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入账号和密码" preferredStyle:UIAlertControllerStyleAlert];
//实例化按钮actionWithTitle
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
NSLog(@"%@",[alert.textFields.firstObject text]);
}]];
//实例化按钮actionWithTitle
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
//添加文本框
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text=self.title;
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField * textField) {
//密文显示
textField.secureTextEntry=YES;
}];
//显示alert
[self presentViewController:alert animated:YES completion:nil];
这是代码实现的结果