NSTextField 设置最大字符数
有没有一种简单的方法可以设置 NSTextField 可以包含的字符数限制?我不想有一个计数器,然后在超出限制时警告用户,我想设置限制,这样如果超过了 x 个字符,他们就无法再输入了。
Is there an easy way for me to set a limit on the amount of characters my NSTextField can have? I don't want to have a counter then warn the user if it's over the limit, I want to set the limit so if it's past x characters that's it, they can't type anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 NSFormatter。它可以帮助您做您正在寻找的事情以及更多。如果您不需要那么复杂的东西,您可以尝试 NSTextField 委托方法。
Check out NSFormatter. It can help you do what you're looking for and a lot more. If you don't need something that complicated, you might try the NSTextField delegate methods.
您可以使用 键值验证以确保最大。长度永远不会超过。
如果输入的长度太长,这将允许您额外通知用户 - 或者您可以悄悄地修改该值。
You could use Key-Value Validation to ensure the max. length is never exceeded.
This would allow you to additionaly notify the user if the entered length was too long - or you could just quietly modify the value.