iOS 强制 UITextfield 使用系统数字键盘

标签 ios objective-c iphone

<分区>

我设置UITextField.UIKeyboardType为Number,但用户可以使用其他公司的键盘; 用户可以点击“返回”按钮,键盘改变KeyboardType。 KeyboardTypeChanged 我想要强制弹出系统数字键盘。 SystemNumberKeyboard

最佳答案

您可以使用 UITextField 委托(delegate)来限制仅输入数字:

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

  let numbersOnly = NSCharacterSet(charactersInString:"0123456789").invertedSet
  let compSepByCharInSet = string.componentsSeparatedByCharactersInSet(numbersOnly)
  let numberFiltered = compSepByCharInSet.joinWithSeparator("")
  return string == numberFiltered

}

关于iOS 强制 UITextfield 使用系统数字键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38850110/

上一篇:php - html5 验证在 iPhone 上不起作用

下一篇:php - 将图像从 iOS 设备上传到 php 服务器时出现问题?(500 内部服务器错误)

相关文章:

iphone - iOS:预览文档时是否可以自定义 "Open in..."菜单?

objective-c - 为什么Camera API仅使用英语? (“取消”,“自动”,“重新拍摄”,“使用”按钮;以及“移动和缩放”标签。)

iPhone:解密错误 "***** with encipherment ccStatus == -4301"

iphone - 闪光灯+手机摄像头

ios - 如何在单击三层时设置 UIBarButtonItem 图像

ios - 如何更好地利用分隔线?例如。让它成为一个细胞?

ios - 防止View进入历史栈

ios - 从基于 alertView 的函数调用 Objective-C 中的函数

ios - 创建太多 AVPlayer 实例时出现 AVPlayerItemStatusFailed 错误

iphone - 应用程序窗口在应用程序启动结束时应该有一个 Root View Controller