一丶切換明文/密文有多余空格

1.png
如圖,會有空白;

3.png
解決方法
- (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];
}
二 切換到密文狀態(tài),再次編輯時,內(nèi)容清空
重現(xiàn):1.切換明密文狀態(tài),最后在密文狀態(tài),再次編輯,輸入任意字符,內(nèi)容清空;
2.其他textField獲取焦點,再切回來(密文狀態(tài)),內(nèi)容清空
解決方法:
- (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];
}
}
//實現(xiàn)代理<UITextFieldDelegate>
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.pswTextField)
{
if (textField.secureTextEntry)
{
[textField insertText:self.pswTextField.text];
}
}
}