- (IBAction)pwdTextSwitch:(UIButton *)sender {

 

    // 前提:在xib中设置按钮的默认与选中状态的背景图 

    // 切换按钮的状态

    sender.selected = !sender.selected;

 

    if (sender.selected) { // 按下去了就是明文

 

        NSString *tempPwdStr = self.pwdInput.text;

        self.pwdInput.text = @""; // 这句代码可以防止切换的时候光标偏移

        self.pwdInput.secureTextEntry = NO;

        self.pwdInput.text = tempPwdStr;

 

    } else { // 暗文

 

        NSString *tempPwdStr = self.pwdInput.text;

        self.pwdInput.text = @"";

        self.pwdInput.secureTextEntry = YES;

        self.pwdInput.text = tempPwdStr;

    }

}

相关文章:

  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-10-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案