|
//
// confimPwdController.m
// ThePaperHD
//
// Created by scar1900 on 15/3/24.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "confimPwdController.h"
#import "MLNavigationController.h"
#import "KGModal.h"
#import "TPCustomButton.h"
@interface confimPwdController ()
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UITextField *passwordField;
@property(nonatomic, strong)UILabel *passwordRangeLabel;
@property(nonatomic, strong)TPCustomButton *confirmBtn;
@end
@implementation confimPwdController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height);
[self.view addSubview:self.closeBtn];
[self.view addSubview:self.titleLabel];
self.closeBtn.frame = CGRectMake(0, 0, 50, 80);
[self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
self.titleLabel.frame = CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
80);
self.keyboardView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.keyboardView.frame = CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), loginPopUpSize.width, loginPopUpSize.height-80);
[self.keyboardView addSubview:self.passwordField];
[self addTextFieldImage];
[self addLine];
[self.keyboardView addSubview:self.passwordRangeLabel];
self.passwordRangeLabel.text = @"请输入6-12个数字或字母";
self.passwordField.text = [TPUserDefault instance].fogetPwdInfoBO.pwd?[TPUserDefault instance].fogetPwdInfoBO.pwd:@"";
[self.keyboardView addSubview:self.confirmBtn];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
[KGModal sharedInstance].tapOutsideToDismiss = NO;
__weak typeof(self) Self = self;
[[KGModal sharedInstance] setTapHandler:^{
[Self closeKeyBoard];
}];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
}
- (UIButton*)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal];
[_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted];
[_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.text = @"忘记密码";
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = appFont(30, NO);
}
return _titleLabel;
}
- (UITextField*)passwordField {
if (!_passwordField) {
_passwordField = [[UITextField alloc]initWithFrame:CGRectMake(50,
55,
loginPopUpSize.width-50-15,
35)];
_passwordField.delegate = self;
_passwordField.backgroundColor = [UIColor clearColor];
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"输入新密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:LINECOLOR]}];
_passwordField.attributedPlaceholder = atrString;
_passwordField.textColor = [UIColor colorWithHexString:TextBlack];
_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 addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
_passwordField.font = appFont(18, NO);
}
return _passwordField;
}
- (UILabel*)passwordRangeLabel {
if(!_passwordRangeLabel) {
_passwordRangeLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.passwordField.frame)-280/2, CGRectGetMaxY(self.passwordField.frame)+7, 280/2, 25/2)];
_passwordRangeLabel.textAlignment = NSTextAlignmentRight;
_passwordRangeLabel.textColor = [UIColor colorWithHexString:LINECOLOR];
_passwordRangeLabel.backgroundColor = [UIColor clearColor];
}
_passwordRangeLabel.font = appFont(22/2, NO);
return _passwordRangeLabel;
}
- (void)addTextFieldImage {
UIImageView *passwordImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15,
CGRectGetMinY(self.passwordField.frame)+2,
25,
55/2)];
passwordImageView.image = Image(@"login/password.png");
[self.keyboardView addSubview:passwordImageView];
}
- (void)addLine {
UIView *pwdLine = [[UIView alloc]initWithFrame:CGRectMake(15,
CGRectGetMaxY(self.passwordField.frame),
CGRectGetWidth(self.view.bounds)-15,
1)];
pwdLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[self.keyboardView addSubview:pwdLine];
}
- (TPCustomButton*)confirmBtn {
if (!_confirmBtn) {
_confirmBtn = [[TPCustomButton alloc]initWithFrame:CGRectMake(190/2,
CGRectGetMaxY(self.passwordRangeLabel.frame)+384/2,
loginPopUpSize.width-190,
40)];
_confirmBtn.title = @"确认";
[_confirmBtn addTarget:self action:@selector(confirmEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmBtn;
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithPush];
}
- (void)textFieldDidChange:(UITextField *)textField {
[TPUserDefault instance].fogetPwdInfoBO.pwd = textField.text;
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
//获取键盘的高度
self.keyboardOffset = 40;
[self.keyboardView setContentOffset:CGPointMake(0, self.keyboardOffset)];
self.keyboardView.scrollEnabled = YES;
}else {
self.keyboardOffset=0;
[self.keyboardView setContentOffset:CGPointMake(0, self.keyboardOffset)];
}
}
- (void)confirmEvent:(UIButton*)btn {
[self closeKeyBoard];
if (![TPUserDefault instance].fogetPwdInfoBO.pwd || isBlankString([TPUserDefault instance].fogetPwdInfoBO.pwd)) {
ShowTextMessage(@"请输入密码");
return;
}
NSDictionary *dic = @{@"mail":[TPUserDefault instance].fogetPwdInfoBO.mail,@"verCode":[TPUserDefault instance].fogetPwdInfoBO.verCode
,@"pwd":[TPUserDefault instance].fogetPwdInfoBO.pwd};
[Remote doJsonActionWithBlock:0
requestUrl:resetPwdURL
parameter:dic
withWaitCursor:YES
completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSDictionary *userInfo = responseData[@"userInfo"];
[TPUserDefault instance].userBO = setJsonDicToDataModel(userInfo, [userBO class]);
/**
* 修复bug:0003598
*/
[TPUserDefault instance].fogetPwdInfoBO= nil;
[self.navigationController popToRootViewControllerAnimated:YES];
}else {
ShowTextMessage(message);
}
}];
}
- (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
|