<span style="font-size:18px;">#import "TRViewController.h"
@interface TRViewController ()
@end
@implementation TRViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (IBAction)creatAlertView:(id)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title" message:@"message here.." preferredStyle:UIAlertControllerStyleAlert];
//将框中显示的按钮独立成了UIAlertAction类型
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *input =(UITextField *)alert.textFields[0];
NSLog(@"%@",input.text);
}];
//将创建的两个按钮添加到警告框中
[alert addAction:cancleAction];
[alert addAction:otherAction];
//添加输入框
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"xxxx";
textField.secureTextEntry = YES;
} ]; //显示警告框
[self presentViewController:alert animated:YES completion:nil];
}
</span>