码迷,mamicode.com
首页 > 其他好文 > 详细

登陆界面的记住密码

时间:2016-03-11 10:10:04      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

//页面一出现则获取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];

 

 

}

登陆界面的记住密码

标签:

原文地址:http://www.cnblogs.com/dcy123/p/5264344.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!