码迷,mamicode.com
首页 > 其他好文 > 详细

UIAlertController

时间:2015-11-04 17:39:43      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view, typically from a nib.
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"一大波僵尸在靠近" preferredStyle:UIAlertControllerStyleAlert];
    
    
    //添加按钮
    __weak typeof(alert) weakAlert = alert;
   [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
       NSLog(@"点击了确定按钮---%@---%@",[weakAlert.textFields.firstObject text],[weakAlert.textFields.lastObject text]);
   }]];
    
   [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
       NSLog(@"点击了取消按钮");
   }]];
    
    //添加文本框
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.text = @"123";
        
        //监听文本框输入的文字内容
        [textField addTarget:self action:@selector(usernameChange:) forControlEvents:UIControlEventAllEditingEvents];
    }];
    
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        
        textField.secureTextEntry = YES;
        textField.text = @"456";
        
        //监听文本框输入的内容
        [textField addTarget:self action:@selector(passwordChande:) forControlEvents:UIControlEventAllEditingEvents];
    }];
    
     [self presentViewController:alert animated:YES completion:nil];
    
}


-(void)usernameChange:(UITextField *)username
{
    NSLog(@"%@",username.text);
}


-(void)passwordChande:(UITextField *)password
{
    NSLog(@"%@",password.text);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

UIAlertController

标签:

原文地址:http://www.cnblogs.com/yzjxdz/p/4936335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!