如何限制 iPhone 上文本字段中文本/数字的长度?

发布于 2024-07-14 07:48:25 字数 141 浏览 11 评论 0原文

我想限制文本字段的长度,以便用户知道他可以输入多少个字符。 但我在iPhone上没有发现textfield有这样的属性。 有什么想法如何做到这一点?

当文本字段达到最大长度时,如何从一个文本字段切换到另一个文本字段? (让用户轻松打字)

I want to limit the length of a textfield, so that a user can know how many characters he can input. But I find no such attributes of textfield on iPhone. Any ideas how to do this?

And how to switch from one textfield to another when it reaches its max length? (to let users type easily)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2024-07-21 07:48:25

您可以查看 UITextFieldDelegate 协议,特别是 textField:shouldChangeCharactersInRange:replacementString:。 您可以检查您的文本字段是否已达到最大大小,如果是,则通过将其发送成为FirstResponder 移动到下一个适当的文本字段:

You might check out the UITextFieldDelegate protocol, specifically textField:shouldChangeCharactersInRange:replacementString:. You could check if your text field has reached it's maximum size, and if so move to the next appropriate text field by sending it becomeFirstResponder:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文