iOS iUITextField的secureTextEntry
2018-07-23 本文已影响62人
翻滚的炒勺2013
1.切换明密文状态,最后在密文状态,再次编辑,输入任意字符,内容清空;
2.其他textField获取焦点,再切回来(密文状态),内容清空
- (IBAction)eyeBtnClick:(UIButton *)sender {
sender.selected = !sender.selected;
self.pswTextField.secureTextEntry = !sender.selected;
NSString *text = self.pswTextField.text;
self.pswTextField.text = @" ";
self.pswTextField.text = text;
if (self.pswTextField.secureTextEntry) {
[self.pswTextField insertText:self.pswTextField.text];
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == self.pswTextField) {
if (textField.secureTextEntry) {
[textField insertText:self.pswTextField.text];
}
}
}