iOS_UITextField_secureTextEntry

作者: 丶纳凉 | 来源:发表于2016-06-29 14:47 被阅读3043次

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

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

三丶

相关文章

  • iOS_UITextField_secureTextEntry

    一丶切换明文/密文有多余空格 如图,会有空白; 解决方法 二 切换到密文状态,再次编辑时,内容清空 重现:1.切换...

网友评论

    本文标题:iOS_UITextField_secureTextEntry

    本文链接:https://www.haomeiwen.com/subject/lskxjttx.html