ios UIAlertController 添加 textfield

这样的效果

ios UIAlertController 添加 textfield_第1张图片
屏幕快照 2017-10-30 14.11.16.png

废话不说,直接贴代码

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"在线转账" message:balance preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder = @"请输入电话号码";
        textField.keyboardType = UIKeyboardTypePhonePad;
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder = @"请输入要转账的金额";
        textField.keyboardType = UIKeyboardTypeDecimalPad;
    }];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        UITextField *phone = alertController.textFields.firstObject;
        UITextField *money = [alertController.textFields objectAtIndex:1];
        
        if (phone.text.length != 11) {
            [PublicMethod showAlert:self message:@"请输入格式正确的电话号码"];
        } else if (money.text != nil){
            // 进行你需要d
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:^{
        
    }];

你可能感兴趣的:(ios UIAlertController 添加 textfield)