登陆界面的记住密码
Posted 蜗牛d
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了登陆界面的记住密码相关的知识,希望对你有一定的参考价值。
//页面一出现则获取NSUserDefaults里面rememberSate的状态来改变UI
-(void)viewWillAppear:(BOOL)animated{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *rememberSate = [userDefaults objectForKey:@"rememberSate"];
if ([rememberSate isEqualToString:@"1"]) {
_rememberBtn.selected = YES;
_usernameTextField.text = [userDefaults objectForKey:@"user_name"];
_passwordTextField.text = [userDefaults objectForKey:@"user_password"];
//记住密码图片显示打勾
[_rememberBtn setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
}else{
_passwordTextField.text = nil;
_usernameTextField.text = nil;
//记住密码图片显示不打勾
[_rememberBtn setImage:[UIImage imageNamed:@"no_check"] forState:UIControlStateNormal];
}
}
//记住密码的点击事件
-(void)btnClick{
//如果选中再点击则不选中
_rememberBtn.selected = !_rememberBtn.selected;
//初始化偏好设置
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (_rememberBtn.selected) {
DDLogInfo(@"记住密码");
[_rememberBtn setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
//如果选中,则存入rememberSate的状态为“1”
[userDefaults setObject:@"1" forKey:@"rememberSate"];
[userDefaults synchronize];
}else{
DDLogInfo(@"取消记住密码");
[_rememberBtn setImage:[UIImage imageNamed:@"no_check"] forState:UIControlStateNormal];
[userDefaults setObject:@"0" forKey:@"rememberSate"];
[userDefaults synchronize];
}
}
//在登陆事件
-(void)loginBtn:(UIButton *)sender{
//登陆成功时
// 存储密码和用户名
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:pwd forKey:@"user_password"];
[userDefaults setObject:userName forKey:@"user_name"];
[userDefaults synchronize];
}
以上是关于登陆界面的记住密码的主要内容,如果未能解决你的问题,请参考以下文章