一丶切换明文/密文有多余空格
如图,会有空白;
解决方法
- (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;
}
或者
[self.pswTextField becomeFirstResponder];
}
二 切换到密文状态,再次编辑时,内容清空
重现: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];
}
}
//实现代理<UITextFieldDelegate>
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.pswTextField)
{
if (textField.secureTextEntry)
{
[textField insertText:self.pswTextField.text];
}
}
}