iPhone 文本字段只有一种输入类型
我的项目中有一些文本字段。
我希望文本字段的输入类型只是一种类型。例如,信用卡号码文本字段的输入只能是小数,并且用户输入其他类型的字符,它将在文本字段中删除或不接受。
抱歉我的英语不好。
I have some text fields on my project.
I want that input types of text fields are only one type. For example credit card number text field's input must be only decimals and user enter another type character, it will remove or not accept in the text field.
Sorry my bad english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须在 textField 的委托中使用 textField:shouldChangeCharactersInRange:replacementString: ,对任何更改返回 YES 或 NO 。您可以分析 replacementString 中是否有禁止的字符,如果发现则拒绝它。
You have to use textField:shouldChangeCharactersInRange:replacementString: in textField's delegate, returning YES or NO for any change. You can analyze replacementString for forbidden characters and reject it if they are found.
你可以像下面这样声明并使用
,我们也可以这样使用
you can declare like the below and use
and we can use like this also
如果您通过代码创建了
UITextField
,那么您需要设置如下:textField.keyboardType = UIKeyboardTypeNumberPad;
If you have created the
UITextField
by code, then you need to set as follows:textField.keyboardType = UIKeyboardTypeNumberPad;