您的位置:首页 > 产品设计 > UI/UE

iOS输入框(UITextField)密码明暗文切换方法

2017-01-17 10:20 976 查看

在做明暗文切换(密码输入框)的时候遇见一个坑,就是切换secureTextEntry的时候,输入框的光标会偏移,下面列出了一个解决办法及一种明暗文切换的方法

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS UITextField 密码
相关文章推荐