Van*_*njo 4 objective-c ipad uikeyboardtype
我正在寻找UIkeyboardtypenumberpad,但在iPad示例中使用.
我的意思是,可以创建一个只模拟数字键盘的类或视图,如iPhone?
我正在使用4.1 sdk版本.
我不想使用特殊字符,只需要数字和点.
谢谢!!
添加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)
| 归档时间: |
|
| 查看次数: |
1434 次 |
| 最近记录: |