iOS_UITextField_secureTextEntry 切换填坑

来源:互联网 发布:网络节点的度 编辑:程序博客网 时间:2024/06/04 17:43

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


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];}

二 切换到密文状态,再次编辑时,内容清空

重现: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];                      }       }}
0 0
原创粉丝点击