UIAlertView:UIAlertViewStyleSecureTextInput:数字键盘

时间:2012-05-14 08:15:06

标签: ios uialertview

我目前正在使用此UIAlertView进行登录弹出,

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Restricted"
                                                message:@"Please Enter Code to Enable Fields" 
                                               delegate:self
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"Login"
                      , nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;

[alert show];

但是我希望文本输入是数字键盘而不是常规键盘

是否有一种简单的方法可以做到这一点,或者我是否需要研究创建自定义UIAleartView

3 个答案:

答案 0 :(得分:51)

您可以尝试更改UIAlertView字段的键盘类型:

[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];

答案 1 :(得分:4)

很酷的答案,但对于iOS 7,我有一点适应

alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] resignFirstResponder];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypePhonePad];
[[alert textFieldAtIndex:0] becomeFirstResponder];

答案 2 :(得分:3)

 UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"Enter File Number" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        alertView1.alertViewStyle = UIKeyboardTypePhonePad;
        myTextField = [alertView1 textFieldAtIndex:0];
        myTextField.keyboardType=UIKeyboardTypeNumberPad;
        [alertView1 setTag:3];
        [alertView1 show];