UIKeyboardTypeNumberPad - Show just numbes on iPad

2020-02-04 07:13发布

UIKeyboardTypeNumberPad doesn't display a number pad on the iPad. Instead, it shows the UIKeyboardTypeNumbersAndPunctuation keyboard.

Is there something I'm missing, or has this been removed from the iPad OS?

Thanks for your guidance!

3条回答
Evening l夕情丶
2楼-- · 2020-02-04 07:49

I believe that this is not currently supported in iPhoneOS 3.2 on the iPad

To quote the UITextInputTraits header file:

//
// UIKeyboardType
//
// Requests that a particular keyboard type be displayed when a text widget
// becomes first responder. 
// Note: Some keyboard/input methods types may not support every variant. 
// In such cases, the input method will make a best effort to find a close 
// match to the requested type (e.g. displaying UIKeyboardTypeNumbersAndPunctuation 
// type if UIKeyboardTypeNumberPad is not supported).
//
查看更多
Anthone
3楼-- · 2020-02-04 07:53

add UITextFieldDelegate in your header file (.h file)

txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;

then add this method

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

 NSString *validRegEx =@"^[0-9]*$"; //change this regular expression as your requirement
 NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];
 BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];
 if (myStringMatchesRegEx)
        return YES;
 else
        return NO;
}
查看更多
对你真心纯属浪费
4楼-- · 2020-02-04 08:05

I know this question has been inactive for quite a while, but this might help somebody out there.

You can try implementing this one https://github.com/azu/NumericKeypad. The coder implemented his own number pad buy subclassing the UITextField

查看更多
登录 后发表回答