【问题标题】:How do I stop UITextField Secure text showing characters如何停止 UITextField 显示字符的安全文本
【发布时间】:2014-07-02 12:37:49
【问题描述】:

我为我的 UITextField 启用了安全文本。在运行时,当我在其中输入一些文本时,我最初会在字符变为项目符号之前看到该字符。有没有办法阻止它显示字符并在我键入时将其作为项目符号。

有什么需要补充的吗

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

有人有例子吗?

【问题讨论】:

  • 这是默认行为
  • 在手机屏幕上,按键空间有限。因此,如果他们像桌面系统一样将子弹直接放在按键上,您无法确定是否添加了正确的字符。因此,对于移动设备,这是一种常见的行为。

标签: ios objective-c uitextfield


【解决方案1】:

我不知道它的好习惯与否,但下面的技巧对我有用

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *editedString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    textField.text = editedString;
    return NO;
}

【讨论】:

    【解决方案2】:

    这是UITextField 的默认行为。因此您无能为力。您可以在编码方面使用某种加密,但在视图方面,这种行为将占上风。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 2021-09-20
      相关资源
      最近更新 更多