// // APPassForgetCodeV.m // westkissMob // // Created by iOS on 2024/4/24. // #import "APPassForgetCodeV.h" #import "KWTextField.h" @interface APPassForgetCodeV () @property (nonatomic, strong) UILabel *detailLab; @property (nonatomic, strong) KWTextField *codeTf; @property (nonatomic, strong) UIButton *xxx_sureBtn; @property (nonatomic, strong) UIButton *resendBtn; @property (nonatomic, strong) UIButton *notReceiveBtn; @property (nonatomic, strong) NSTimer *timer; @property (nonatomic, assign) NSInteger totalTime; @end @implementation APPassForgetCodeV - (void)timerAction { self.totalTime -= 1; BOOL cantabel = self.totalTime > 0; NSString *titleStr = cantabel ? [NSString stringWithFormat:@"%lds",self.totalTime] : @"Resend"; [self.resendBtn setTitle:titleStr forState:UIControlStateNormal]; self.resendBtn.backgroundColor = cantabel ? Col_666 : Col_000; self.resendBtn.enabled = !cantabel; if (!cantabel) { [self.timer invalidate]; self.timer = nil; } } - (void)setEmailAddr:(NSString *)emailAddr { _emailAddr = emailAddr; NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Enter The Verification Code Below To Reset Your Password Within 30 Minutes."]]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.alignment = NSTextAlignmentCenter; style.lineSpacing = 6; [att setAttributes:@{ NSParagraphStyleAttributeName:style, NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:14], NSForegroundColorAttributeName:[UIColor blackColor], }]; // [att addAttribute:NSForegroundColorAttributeName value:_FF5900 range:[att.string rangeOfString:self.emailAddr]]; self.detailLab.attributedText = att; } - (void)action_submitClick:(UIButton *)bt { [bt sleep:1]; NSString *code = self.codeTf.text; if (code == nil || code.isEmpty) { [self makeToast:@"The Code Can't Be Empty"]; return; } if (self.subBtnClick) { self.subBtnClick(code); } } - (void)resendBtAction:(UIButton *)bt { [bt sleep:1]; self.totalTime = 60; self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:true]; if (self.resendBtnClick) { self.resendBtnClick(); } } - (void)noreceiveBtAction:(UIButton *)bt { [bt sleep:1]; if (self.noReceiveClick) { self.noReceiveClick(); } } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self loadSubV]; } return self; } - (void)loadSubV { UILabel *titileLab = [UILabel new]; titileLab.text = @"RESET PASSWORD"; titileLab.font = [UIFont boldSystemFontOfSize:16]; titileLab.textAlignment = NSTextAlignmentCenter; titileLab.textColor = [UIColor colorWithHexString:@"#000000"]; [self addSubview:titileLab]; UILabel *detailLab = [UILabel baseLb]; detailLab.textAlignment = NSTextAlignmentCenter; detailLab.font = [UIFont fontWithName:Rob_Regular size:14]; detailLab.numberOfLines = 0; [self addSubview:detailLab]; self.detailLab = detailLab; [titileLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@40); make.leading.equalTo(self).offset(30); make.trailing.equalTo(self).offset(-30); }]; [detailLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titileLab.mas_bottom).offset(40); make.leading.equalTo(self).offset(30); make.trailing.equalTo(self).offset(-30); }]; [self addSubviews:@[self.codeTf, self.resendBtn]]; [self.codeTf mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(detailLab.mas_bottom).offset(40); make.leading.equalTo(@20); make.height.equalTo(@45); }]; [self.resendBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@82); make.top.bottom.equalTo(self.codeTf); make.leading.equalTo(self.codeTf.mas_trailing); make.trailing.equalTo(self).offset(-20); }]; [self addSubview:self.xxx_sureBtn]; [self addSubview:self.notReceiveBtn]; [self.xxx_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.codeTf.mas_bottom).offset(30); make.leading.equalTo(@20); make.trailing.equalTo(self).offset(-20); make.height.equalTo(@45); }]; [self.notReceiveBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.xxx_sureBtn.mas_bottom).offset(13); make.leading.equalTo(@30); make.trailing.equalTo(self).offset(-30); make.height.equalTo(@28); make.bottom.equalTo(self).offset(-30); }]; } - (KWTextField *)codeTf { if (!_codeTf) { KWTextField *tf = [[KWTextField alloc] init]; tf.placeholder = @"Enter The Code"; _codeTf = tf; } return _codeTf; } -(UIButton *)xxx_sureBtn{ if (!_xxx_sureBtn) { _xxx_sureBtn = [TT_ControlTool FTT_ControlToolUIButtonFrame:CGRectMake(0,0 ,SCREEN_WIDTH-40,50) taeget:self sel:@selector(action_submitClick:) tag:0 AntTitle:@"SUBMIT" titleFont:17 titleColor:[UIColor whiteColor] andImage:nil AndBackColor:nil adjustsFontSizesTowidth:NO masksToBounds:YES conrenRadius:5 BorderColor:nil BorderWidth:0 ContentHorizontalAligment:0]; _xxx_sureBtn.backgroundColor = [UIColor blackColor]; } return _xxx_sureBtn; } - (UIButton *)notReceiveBtn { if (!_notReceiveBtn) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:@"I Didn’t Receive Your Email Yet"]; [att setAttributes:@{ NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:12], NSForegroundColorAttributeName:[UIColor blackColor], NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle), }]; [bt setAttributedTitle:att forState:UIControlStateNormal]; bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12]; [bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [bt addTarget:self action:@selector(noreceiveBtAction:) forControlEvents:UIControlEventTouchUpInside]; _notReceiveBtn = bt; } return _notReceiveBtn; } - (UIButton *)resendBtn { if (!_resendBtn) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt setTitle:@"Resend" forState:UIControlStateNormal]; bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:14]; [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [bt setBackgroundColor:[UIColor colorWithHexString:@"#000000"]]; [bt addTarget:self action:@selector(resendBtAction:) forControlEvents:UIControlEventTouchUpInside]; _resendBtn = bt; } return _resendBtn; } @end