123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // 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 ()<UITextFieldDelegate>
- @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<UITouch *> *)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
|