Jus*_*tin 18 iphone cocoa-touch uikit ipad
UIKeyboardTypeNumberPad在iPad上不显示数字键盘.而是显示UIKeyboardTypeNumbersAndPunctuation键盘.
有没有我遗失的东西,或者是否已将其从iPad OS中移除?
谢谢你的指导!
Dus*_*ett 14
我相信目前iPad上的iPhoneOS 3.2不支持此功能
引用UITextInputTraits头文件:
//
// 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).
//
Run Code Online (Sandbox Code Playgroud)
添加UITextFieldDelegate您的头文件(.h文件)
txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;
Run Code Online (Sandbox Code Playgroud)
然后添加此方法
- (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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8555 次 |
| 最近记录: |