APPassForgetCodeV.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // APPassForgetCodeV.m
  3. // westkissMob
  4. //
  5. // Created by iOS on 2024/4/24.
  6. //
  7. #import "APPassForgetCodeV.h"
  8. #import "KWTextField.h"
  9. @interface APPassForgetCodeV ()
  10. @property (nonatomic, strong) UILabel *detailLab;
  11. @property (nonatomic, strong) KWTextField *codeTf;
  12. @property (nonatomic, strong) UIButton *xxx_sureBtn;
  13. @property (nonatomic, strong) UIButton *resendBtn;
  14. @property (nonatomic, strong) UIButton *notReceiveBtn;
  15. @property (nonatomic, strong) NSTimer *timer;
  16. @property (nonatomic, assign) NSInteger totalTime;
  17. @end
  18. @implementation APPassForgetCodeV
  19. - (void)timerAction {
  20. self.totalTime -= 1;
  21. BOOL cantabel = self.totalTime > 0;
  22. NSString *titleStr = cantabel ? [NSString stringWithFormat:@"%lds",self.totalTime] : @"Resend";
  23. [self.resendBtn setTitle:titleStr forState:UIControlStateNormal];
  24. self.resendBtn.backgroundColor = cantabel ? Col_666 : Col_000;
  25. self.resendBtn.enabled = !cantabel;
  26. if (!cantabel) {
  27. [self.timer invalidate];
  28. self.timer = nil;
  29. }
  30. }
  31. - (void)setEmailAddr:(NSString *)emailAddr {
  32. _emailAddr = emailAddr;
  33. NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Enter The Verification Code Below To Reset Your Password Within 30 Minutes."]];
  34. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  35. style.alignment = NSTextAlignmentCenter;
  36. style.lineSpacing = 6;
  37. [att setAttributes:@{
  38. NSParagraphStyleAttributeName:style,
  39. NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:14],
  40. NSForegroundColorAttributeName:[UIColor blackColor],
  41. }];
  42. // [att addAttribute:NSForegroundColorAttributeName value:_FF5900 range:[att.string rangeOfString:self.emailAddr]];
  43. self.detailLab.attributedText = att;
  44. }
  45. - (void)action_submitClick:(UIButton *)bt {
  46. [bt sleep:1];
  47. NSString *code = self.codeTf.text;
  48. if (code == nil || code.isEmpty) {
  49. [self makeToast:@"The Code Can't Be Empty"];
  50. return;
  51. }
  52. if (self.subBtnClick) {
  53. self.subBtnClick(code);
  54. }
  55. }
  56. - (void)resendBtAction:(UIButton *)bt {
  57. [bt sleep:1];
  58. self.totalTime = 60;
  59. self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
  60. if (self.resendBtnClick) {
  61. self.resendBtnClick();
  62. }
  63. }
  64. - (void)noreceiveBtAction:(UIButton *)bt {
  65. [bt sleep:1];
  66. if (self.noReceiveClick) {
  67. self.noReceiveClick();
  68. }
  69. }
  70. - (instancetype)initWithFrame:(CGRect)frame
  71. {
  72. self = [super initWithFrame:frame];
  73. if (self) {
  74. [self loadSubV];
  75. }
  76. return self;
  77. }
  78. - (void)loadSubV {
  79. UILabel *titileLab = [UILabel new];
  80. titileLab.text = @"RESET PASSWORD";
  81. titileLab.font = [UIFont boldSystemFontOfSize:16];
  82. titileLab.textAlignment = NSTextAlignmentCenter;
  83. titileLab.textColor = [UIColor colorWithHexString:@"#000000"];
  84. [self addSubview:titileLab];
  85. UILabel *detailLab = [UILabel baseLb];
  86. detailLab.textAlignment = NSTextAlignmentCenter;
  87. detailLab.font = [UIFont fontWithName:Rob_Regular size:14];
  88. detailLab.numberOfLines = 0;
  89. [self addSubview:detailLab];
  90. self.detailLab = detailLab;
  91. [titileLab mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.equalTo(@40);
  93. make.leading.equalTo(self).offset(30);
  94. make.trailing.equalTo(self).offset(-30);
  95. }];
  96. [detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.equalTo(titileLab.mas_bottom).offset(40);
  98. make.leading.equalTo(self).offset(30);
  99. make.trailing.equalTo(self).offset(-30);
  100. }];
  101. [self addSubviews:@[self.codeTf, self.resendBtn]];
  102. [self.codeTf mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.top.equalTo(detailLab.mas_bottom).offset(40);
  104. make.leading.equalTo(@20);
  105. make.height.equalTo(@45);
  106. }];
  107. [self.resendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.width.equalTo(@82);
  109. make.top.bottom.equalTo(self.codeTf);
  110. make.leading.equalTo(self.codeTf.mas_trailing);
  111. make.trailing.equalTo(self).offset(-20);
  112. }];
  113. [self addSubview:self.xxx_sureBtn];
  114. [self addSubview:self.notReceiveBtn];
  115. [self.xxx_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.top.equalTo(self.codeTf.mas_bottom).offset(30);
  117. make.leading.equalTo(@20);
  118. make.trailing.equalTo(self).offset(-20);
  119. make.height.equalTo(@45);
  120. }];
  121. [self.notReceiveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.top.equalTo(self.xxx_sureBtn.mas_bottom).offset(13);
  123. make.leading.equalTo(@30);
  124. make.trailing.equalTo(self).offset(-30);
  125. make.height.equalTo(@28);
  126. make.bottom.equalTo(self).offset(-30);
  127. }];
  128. }
  129. - (KWTextField *)codeTf {
  130. if (!_codeTf) {
  131. KWTextField *tf = [[KWTextField alloc] init];
  132. tf.placeholder = @"Enter The Code";
  133. _codeTf = tf;
  134. }
  135. return _codeTf;
  136. }
  137. -(UIButton *)xxx_sureBtn{
  138. if (!_xxx_sureBtn) {
  139. _xxx_sureBtn = [TT_ControlTool FTT_ControlToolUIButtonFrame:CGRectMake(0,0 ,SCREEN_WIDTH-40,50)
  140. taeget:self
  141. sel:@selector(action_submitClick:)
  142. tag:0
  143. AntTitle:@"SUBMIT"
  144. titleFont:17
  145. titleColor:[UIColor whiteColor]
  146. andImage:nil
  147. AndBackColor:nil
  148. adjustsFontSizesTowidth:NO
  149. masksToBounds:YES
  150. conrenRadius:5
  151. BorderColor:nil
  152. BorderWidth:0
  153. ContentHorizontalAligment:0];
  154. _xxx_sureBtn.backgroundColor = [UIColor blackColor];
  155. }
  156. return _xxx_sureBtn;
  157. }
  158. - (UIButton *)notReceiveBtn {
  159. if (!_notReceiveBtn) {
  160. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  161. NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:@"I Didn’t Receive Your Email Yet"];
  162. [att setAttributes:@{
  163. NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:12],
  164. NSForegroundColorAttributeName:[UIColor blackColor],
  165. NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),
  166. }];
  167. [bt setAttributedTitle:att forState:UIControlStateNormal];
  168. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  169. [bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  170. [bt addTarget:self action:@selector(noreceiveBtAction:) forControlEvents:UIControlEventTouchUpInside];
  171. _notReceiveBtn = bt;
  172. }
  173. return _notReceiveBtn;
  174. }
  175. - (UIButton *)resendBtn {
  176. if (!_resendBtn) {
  177. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  178. [bt setTitle:@"Resend" forState:UIControlStateNormal];
  179. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:14];
  180. [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  181. [bt setBackgroundColor:[UIColor colorWithHexString:@"#000000"]];
  182. [bt addTarget:self action:@selector(resendBtAction:) forControlEvents:UIControlEventTouchUpInside];
  183. _resendBtn = bt;
  184. }
  185. return _resendBtn;
  186. }
  187. @end