热更新demo

confimPwdController.m 7.5KB

    // // confimPwdController.m // ThePaperBase // // Created by Huixin on 15/8/20. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "confimPwdController.h" #import "userSystemViewModel.h" @interface confimPwdController () <UITextFieldDelegate, userSystemViewModel> @property(nonatomic, strong)UIImageView *passwordImageView; @property(nonatomic, strong)UITextField *passwordField; @property(nonatomic, strong)UIView *passwordLine; @property(nonatomic, strong)UILabel *passwordLabel; @property(nonatomic, strong)TPCustomButton *confirmBtn; @property(nonatomic, strong)userSystemViewModel *viewModel; @end @implementation confimPwdController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleStr = @"忘记密码"; _viewModel = [userSystemViewModel new]; _viewModel.delegate = self; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; [self.view addGestureRecognizer:tapGesture]; [self.view addSubview:self.passwordImageView]; [self.view addSubview:self.passwordField]; [self.view addSubview:self.passwordLine]; [self.view addSubview:self.passwordLabel]; [self.view addSubview:self.confirmBtn]; [self.passwordField becomeFirstResponder]; [self layoutViews]; } - (void)layoutViews { [self.passwordImageView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left).offset(20); make.bottom.equalTo(self.passwordField.bottom); make.width.mas_equalTo(@18); make.height.mas_equalTo(@20); }]; [self.passwordField makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.naviBar.bottom).offset(38); make.left.equalTo(self.view.left).offset(50); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@19); }]; [self.passwordLine makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordField.bottom).offset(7); make.left.equalTo(self.passwordImageView.left); make.right.equalTo(self.passwordField.right); make.height.mas_equalTo(@1); }]; [self.passwordLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordLine.bottom).offset(4); make.left.equalTo(self.passwordLine.left); make.right.equalTo(self.passwordLine.right); make.height.mas_equalTo(12); }]; [self.confirmBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordLabel.bottom).offset(45); make.left.equalTo(self.view.left).offset(20); make.right.equalTo(self.view.right).offset(-20); make.height.equalTo(self.confirmBtn.width).multipliedBy(0.15); }]; } #pragma mark - get method - (UIImageView*)passwordImageView { if (!_passwordImageView) { _passwordImageView = [[UIImageView alloc] init]; _passwordImageView.image = Image(@"login/password.png"); } return _passwordImageView; } - (UITextField*)passwordField { if (!_passwordField) { _passwordField = [[UITextField alloc] init]; _passwordField.backgroundColor = [UIColor clearColor]; NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"输入新密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}]; _passwordField.attributedPlaceholder = atrString; // _passwordField.text = [TPUserDefault instance].registerBO.pwd?[TPUserDefault instance].registerBO.pwd:@""; _passwordField.textColor = [UIColor colorWithHexString:TextBlack]; _passwordField.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _passwordField.textAlignment = NSTextAlignmentLeft; _passwordField.keyboardAppearance = UIKeyboardAppearanceDefault; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _passwordField.keyboardAppearance = UIKeyboardAppearanceDark; } _passwordField.keyboardType = UIKeyboardTypeASCIICapable; _passwordField.secureTextEntry = YES; _passwordField.clearButtonMode = UITextFieldViewModeWhileEditing; _passwordField.delegate = self; [_passwordField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; _passwordField.returnKeyType = UIReturnKeyDone; //bug:5035 关于密码的地方,键盘都改成“确定” } return _passwordField; } - (UIView*)passwordLine { if (!_passwordLine) { _passwordLine = [[UIView alloc] init]; _passwordLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _passwordLine; } - (UILabel*)passwordLabel { if (!_passwordLabel) { _passwordLabel = [[UILabel alloc] init]; _passwordLabel.backgroundColor = [UIColor clearColor]; _passwordLabel.text = passwordRangeHolder; _passwordLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _passwordLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _passwordLabel.textAlignment = NSTextAlignmentRight; } return _passwordLabel; } - (TPCustomButton*)confirmBtn { if (!_confirmBtn) { _confirmBtn = [[TPCustomButton alloc] init]; _confirmBtn.title = @"完成"; [_confirmBtn addTarget:self action:@selector(confirmEvent) forControlEvents:UIControlEventTouchUpInside]; } return _confirmBtn; } #pragma mark - textfield delegate - (void)textFieldDidChange:(UITextField *)textField { if (textField == self.passwordField) { if ([textField.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) { textField.text = disable_emoji(textField.text); } [TPUserDefault instance].fogetPwdInfoBO.pwd = textField.text; } } - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == _passwordField) { [self confirmEvent]; } return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([textField isFirstResponder]) { if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) { return NO; } } return YES; } #pragma mark - btn event handler - (void)confirmEvent { [self closeKeyBoard]; [_viewModel confirmModifyPassword]; } #pragma mark - viewmodel delegate - (void)modifyPasswordSuccess { ShowTextMessage(@"密码设置成功"); [[NSNotificationCenter defaultCenter] postNotificationName:HAVELOGIN object:nil]; } #pragma mark - tap handler - (void)tap:(UITapGestureRecognizer*)sender { [self closeKeyBoard]; } #pragma mark - keyBoard event - (void)closeKeyBoard { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (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