iOS alertController自帶的輸入框

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"請輸入支付密碼" preferredStyle:UIAlertControllerStyleAlert];

    //增長取消按鈕;

    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

 

    }]];

 

    //增長肯定按鈕;

    [alertController addAction:[UIAlertAction actionWithTitle:@"肯定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        //獲取第1個輸入框;

        

        UITextField *userNameTextField = alertController.textFields.firstObject;

        NSLog(@"支付密碼 = %@",userNameTextField.text);

    }]];

    

    //定義第一個輸入框;

    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

        textField.placeholder = @"請輸入支付密碼";

        textField.secureTextEntry = YES;

    }];

    

    [self presentViewController:alertController animated:true completion:nil];
相關文章
相關標籤/搜索