简体   繁体   English

UITextField隐藏所有字符

[英]UITextField hide all characters

Our customers want a Textfield for a Password which is not showing any character while typing. 我们的客户想要一个密码的Textfield ,在输入时不显示任何字符。

Is there any Setting in iOS to activate this behaviour or is it possible to hide also the last typed character using the secureTextEntry property on a UITextField ? iOS中是否有任何设置可以激活此行为,或者是否可以使用UITextField上的secureTextEntry属性隐藏最后输入的字符?

You can set your view controller as delegate for your text field, and add the following method, this will not allow the text field to show that last character: 您可以将视图控制器设置为文本字段的委托,并添加以下方法,这将不允许文本字段显示最后一个字符:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField == self.pinTextField) {
        NSString *currentText = textField.text;
        NSString *newText = [currentText stringByReplacingCharactersInRange:range withString:string];
        textField.text = newText;
        return NO;
    }
    return YES;
}

please check below image attachement. 请查看下面的图片附件。

When you put uitextfield in your storyboard or xib. 当你将uitextfield放在storyboard或xib中时。 then after select that uitextfield & you can see the properties list in your right side of xcode. 然后选择uitextfield后,您可以在xcode的右侧看到属性列表。 Now you can see the second image type of propeties in your properties list. 现在,您可以在属性列表中看到第二种图像类型的属性。 Now true check box for secure text entry. 现在是用于安全文本输入的真实复选框。 when you select it then after you can see the first image type of entries in you app. 当您选择它时,您可以在您的应用程序中看到第一个图像类型的条目。

在此输入图像描述

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM