// // Message_Set_VC.m // jiaPei // // Created by EchoShacolee on 2017/1/17. // Copyright © 2017年 JCZ. All rights reserved. // #import "Message_Set_VC.h" #define kAlphaNum @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+..<>{}[];:/?\'|"//限制输入字符类型 @interface Message_Set_VC () @property (weak, nonatomic) IBOutlet UITextField *pwdTextField; @property (weak, nonatomic) IBOutlet UIButton *eyeButton; @property (weak, nonatomic) IBOutlet UIButton *sureButton; @property (weak, nonatomic) IBOutlet UIButton *giveUpBtn; @end @implementation Message_Set_VC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"设置新密码"; self.view.backgroundColor = backGroundColor; [self configNavigationBar]; [_sureButton setTitleColor:defGreen forState:UIControlStateNormal]; [_giveUpBtn setTitleColor:defGreen forState:UIControlStateNormal]; self.pwdTextField.delegate = self; _pwdTextField.secureTextEntry = YES; [_eyeButton setImage:[UIImage imageNamed:@"closeEye"] forState:UIControlStateNormal]; [_eyeButton setImage:[UIImage imageNamed:@"passEye"] forState:UIControlStateSelected];} //明暗文切换 - (IBAction)eyeBtnClick:(id)sender { _eyeButton.selected = !_eyeButton.isSelected; _pwdTextField.secureTextEntry = _pwdTextField.secureTextEntry ? NO : YES; } //确定修改 - (IBAction)sureBtnClick:(id)sender { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } //判断密码长度 if (_pwdTextField.text.length < 6) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"密码长度不能少于6个字符" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"loginCode" Value:self.loginCode]; [arr addPro:@"pwd" Value:_pwdTextField.text]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; NSString* method = @"savePwdN"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; //NSLog(@"密码返回数据->%@",root); if (!root) { ShowMsgFailed(); return; } if ( 1 == [root[@"code"] integerValue]) { ShowMsg(root[@"body"]); return; } showMsgByAlertWithSureBlock(self, @"密码重置成功", ^{ //回到登录页 [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; }); }]; } //放弃修改 - (IBAction)giveUpBtnClick:(id)sender { //回到登录页 [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; if ([_pwdTextField isFirstResponder]) { [_pwdTextField resignFirstResponder]; } } #pragma mark - 限制输入字符 //输入限制 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; { //先设置只能输入的集合 invertedSet就是将咱们允许输入的字符串的字符找出 NSCharacterSet *canInputSet = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet]; //把允许输入的内容转化成数组,再转化成字符串 NSString *str = [[string componentsSeparatedByCharactersInSet:canInputSet] componentsJoinedByString:@""]; //判断输入的字符是否包含在允许输入的字符之内 BOOL isSuccess = [string isEqualToString:str]; //限制文本框输入内容的长度不得超过10且有输入内容的限制 if (textField.text.length <= 20 && isSuccess){ //返回值为YES的时候,文本框可以进行编辑 return YES; }else{ if (!isSuccess) { return NO; }else{ if (str.length == 0) { return YES;//保证删除功能 } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"密码不能超出20位" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; return NO; } //当返回NO的时候,文本框内的内容不会在再改变 return NO; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end