Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 730
werderpoddi Avatar asked Jul 22 '15 09:07

werderpoddi


People also ask

How to limit the number of characters in a UITextField or UITextView?

If you have a UITextField or UITextView and want to stop users typing in more than a certain number of letters, you need to set yourself as the delegate for the control then implement either shouldChangeCharactersIn (for text fields) or shouldChangeTextIn (for text views).

How do I hide textField in Swift?

If you have a UITextField and you want to hide the keyboard when the user is pressing the return key, use the textFieldShouldReturn function. Be sure you have set the textField. delegate = self in your viewDidLoad() function.

What is UITextField in swift?

An object that displays an editable text area in your interface.


1 Answers

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;
}
like image 180
Levi Avatar answered Oct 19 '22 23:10

Levi