iOS文本字段,仅在键盘上显示字母,数字和一些标点符号 [英] iOS text field, show only letters, numbers and some punctuation on the keyboard

查看:287
本文介绍了iOS文本字段,仅在键盘上显示字母,数字和一些标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 5中,我希望有一个用户名的文本字段。如果键盘只显示字母和数字(可能只有1个标点字符,或者只是字母),那将是一件好事。也许不允许使用的字符可能会变灰。

In iOS 5 I wish to have a text field for a user's name. It would be good to have a keyboard that displays only letters and numbers (and maybe 1 punctuation character, or maybe just letters). Perhaps characters not allowed to be used could be greyed out.

此功能是否可行?或者有更好的方法吗?

Is this functionality possible? Or is there a better way to do it?

谢谢: - )

推荐答案

你有一个

-(BOOL)textField:(UITextField *)textField 
       shouldChangeCharactersInRange:(NSRange)range 
       replacementString:(NSString *)string;

UITextFieldDelegate 协议中的方法。如果您将返回NO,则不会接受更改,因此保留上次输入之前的文本。所以基本上你只需要在里面实现你的接受逻辑。

method in UITextFieldDelegate protocol. If you'll return NO the change will not be accepted thus leaving text as it was before last input. So basically you just need to implement your acceptance logic inside.

希望它有所帮助。

这篇关于iOS文本字段,仅在键盘上显示字母,数字和一些标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆