35、输入框(UITextField)密码明暗文切换

- (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;

    }

}

原文地址:https://www.cnblogs.com/qiangzheVSruozhe/p/6839262.html