<分区>
标签 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/
相关文章:
iphone - iOS:预览文档时是否可以自定义 "Open in..."菜单?
objective-c - 为什么Camera API仅使用英语? (“取消”,“自动”,“重新拍摄”,“使用”按钮;以及“移动和缩放”标签。)
iPhone:解密错误 "***** with encipherment ccStatus == -4301"
ios - 如何在单击三层时设置 UIBarButtonItem 图像
ios - 从基于 alertView 的函数调用 Objective-C 中的函数