当键盘处于活动状态时,如何隐藏 iPhone 上的文本字段光标
我们正在尝试使用此方法进行密码设置,以便用户不应该看到光标。
we are trying this for password settings,so that cursor should not be visible to user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试设置 字段的
secureTextEntry
属性 为YES
。Try setting the field's
secureTextEntry
property toYES
.编辑:要回答这个问题,隐藏光标最简单的方法是用另一个
UITextField
覆盖UITextField
,其中后面的实际上是第一个响应者,前面的响应者至少会接收焦点(使用-(void)textFieldDidBeginEditing:(UITextField *)textField
并传递焦点)。 准确地在前面的
UITextField
上应用替换,使用类似You 的东西可能会以这种方式破坏复制和粘贴功能。另外,在这些委托函数中执行的操作要非常小心。期待意想不到的事情。
我原来的答案,同样适用:
我不知道在这种情况下“高级安全性”意味着什么,但看看
更改 uitextfield 中的安全密码字符
要进一步破坏用户体验,并可能添加更多“安全性”,您可以:
禁用退格功能NO
if[string length] == 0
1+(arc4rand()%4)
个字符(如在某些窗口系统上看到的),但我必须说我真的不明白这一切的意义。
edit: to answer the question though, hiding the cursor is done easiest by overlaying the
UITextField
with anotherUITextField
, where the back one is actually the first responder, and the front one acts to at least receive focus (using-(void)textFieldDidBeginEditing:(UITextField *)textField
, and passing focus on). Inapply the replacement on the front
UITextField
exactly, using something likeYou will probably break copy&paste functionality this way. Also, be very careful what you do in those delegate functions. Expect the unexpected.
My original answer, equally applicable:
I don't know what "advanced security" in this context would mean, but have a look at
change the secure password character in uitextfield
To ruin the user experience even more, and maybe add more "security", you could:
NO
if[string length] == 0
1+(arc4rand()%4)
characters for every character entered (as seen on some windowing systems)but I must say that I really don't see the point of all this.
您可以使用隐藏的虚拟文本字段,并使用 TextField 的委托 textDidChage 并使用该值填充实际密码字段中的屏蔽值。
在 Interface Builder 中有一个隐藏的虚拟文本字段,为该字段维护一个 IBOutlet,比如
IBOutlet UITextField *passwordField;
IBOutlet UItextField *dummyField;
还为此设置委托并编写以下委托方法
You can use dummy text field which is hidden and use the delegate textDidChage for TextField and use this value to fill the Masked Values in actual Password field.
In Interface Builder have a dummy textfield which is hidden, maintain a IBOutlet for that say
IBOutlet UITextField *passwordField;
IBOutlet UItextField *dummyField;
Also set delegate for this and write the following delegate methods
我也遇到了这个问题。我使用了所描述的解决方案
此处
它替换了具有自定义 UILabel 的 UITextField 进行以下调整:
I had this problem too.I used the solution described
here
It replaces the UITextField with a custom UILabel with the following adjustments: