【问题标题】:UIKeyboardTypeNumberPad - Show just numbes on iPad?UIKeyboardType Number Pad - 在 iPad 上只显示数字?
【发布时间】:2012-06-29 16:50:05
【问题描述】:

UIKeyboardTypeNumberPad 在 iPad 上不显示数字键盘。相反,它显示 UIKeyboardTypeNumbersAndPunctuation 键盘。

是我遗漏了什么,还是从 iPad 操作系统中删除了?

感谢您的指导!

【问题讨论】:

标签: iphone cocoa-touch uikit ipad


【解决方案1】:

我认为 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).
//

【讨论】:

  • 但我已经看到它在 iPad 上的弹出框内完成。他们是怎么做到的?
  • 他们可能只是自己实现了它。
【解决方案2】:

在头文件(.h 文件)中添加UITextFieldDelegate

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

然后添加这个方法

- (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;
}

【讨论】:

  • 这不会按照问题的要求进行(仅在 iPad 上显示数字),而是使用默认键盘(带有字母等)并限制输入,以便仅显示数字允许。
【解决方案3】:

我知道这个问题已经有一段时间不活跃了,但这可能会对那里的人有所帮助。

您可以尝试实现这个https://github.com/azu/NumericKeypad。编码器实现了他自己的数字键盘购买子类化 UITextField

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多