简体   繁体   中英

UITextField hide all characters

Our customers want a Textfield for a Password which is not showing any character while typing.

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 ?

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. then after select that uitextfield & you can see the properties list in your right side of 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.

在此输入图像描述

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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