ModifyPWDFirstViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // ModifyPWDFirstViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "ModifyPWDFirstViewController.h"
  8. #import <Masonry.h>
  9. #import "ModifyPWDSecondViewController.h"
  10. @interface ModifyPWDFirstViewController (){
  11. NSString *pwd;
  12. UILabel *pointView0;
  13. UILabel *pointView1;
  14. UILabel *pointView2;
  15. UILabel *pointView3;
  16. UIButton *keyBoardBtn0;
  17. }
  18. @end
  19. @implementation ModifyPWDFirstViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. pwd = @"";
  24. [self drawAnyView];
  25. }
  26. - (void)drawAnyView{
  27. [self.navigationBar setHidden:YES];
  28. [self.toolBar setHidden:YES];
  29. [self.view setBackgroundColor:HWF5F7FAColor];
  30. /*添加取消按钮*/
  31. UIButton *upStepBtn = [[UIButton alloc] init];
  32. [upStepBtn setTitle:NSLocalizedString(@"other_cancel",nil) forState:(UIControlStateNormal)];
  33. [upStepBtn setTitleColor:HW05BAFBColor forState:(UIControlStateNormal)];
  34. [upStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  35. [upStepBtn addTarget:self.navigationController
  36. action:@selector(popViewControllerAnimated:)
  37. forControlEvents:(UIControlEventTouchUpInside)];
  38. [self.view addSubview:upStepBtn];
  39. [upStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.right.mas_equalTo(-10.f);
  41. make.width.mas_equalTo(78.f);
  42. make.top.mas_equalTo(5.f + H_STATE_BAR);
  43. make.height.mas_equalTo(32.f);
  44. }];
  45. /*设置密码标题*/
  46. UILabel *topLabel = [[UILabel alloc] init];
  47. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  48. [topLabel setTextColor:HW333333Color];
  49. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  50. [topLabel setText:NSLocalizedString(@"my_set_no_reset_pwd_title",nil)];
  51. [self.view addSubview:topLabel];
  52. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(20);
  54. make.right.mas_equalTo(-20);
  55. make.top.mas_equalTo(99.f + H_STATE_BAR);
  56. }];
  57. CGFloat w_pwd = 24.f;
  58. CGFloat h_pwd = 24.f;
  59. CGFloat pointFont = 20.f;
  60. /*密码视图*/
  61. pointView0 = [[UILabel alloc] init];
  62. [pointView0 setTextColor:HW0A132BColor];
  63. [pointView0 setBackgroundColor:HWE3E8F1Color];
  64. [pointView0 setClipsToBounds:YES];
  65. [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
  66. [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
  67. [pointView0.layer setCornerRadius:w_pwd/2.f];
  68. [self.view addSubview:pointView0];
  69. [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  71. make.height.mas_equalTo(h_pwd);
  72. make.width.mas_equalTo(w_pwd);
  73. make.top.mas_equalTo(151.f + H_STATE_BAR);
  74. }];
  75. pointView1 = [[UILabel alloc] init];
  76. [pointView1 setTextColor:HW0A132BColor];
  77. [pointView1 setBackgroundColor:HWE3E8F1Color];
  78. [pointView1 setClipsToBounds:YES];
  79. [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
  80. [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
  81. [pointView1.layer setCornerRadius:w_pwd/2.f];
  82. [self.view addSubview:pointView1];
  83. [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  85. make.height.mas_equalTo(h_pwd);
  86. make.width.mas_equalTo(w_pwd);
  87. make.top.mas_equalTo(151.f + H_STATE_BAR);
  88. }];
  89. pointView2 = [[UILabel alloc] init];
  90. [pointView2 setTextColor:HW0A132BColor];
  91. [pointView2 setBackgroundColor:HWE3E8F1Color];
  92. [pointView2 setClipsToBounds:YES];
  93. [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
  94. [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
  95. [pointView2.layer setCornerRadius:w_pwd/2.f];
  96. [self.view addSubview:pointView2];
  97. [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  99. make.height.mas_equalTo(h_pwd);
  100. make.width.mas_equalTo(w_pwd);
  101. make.top.mas_equalTo(151.f + H_STATE_BAR);
  102. }];
  103. pointView3 = [[UILabel alloc] init];
  104. [pointView3 setTextColor:HW0A132BColor];
  105. [pointView3 setBackgroundColor:HWE3E8F1Color];
  106. [pointView3 setClipsToBounds:YES];
  107. [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
  108. [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
  109. [pointView3.layer setCornerRadius:w_pwd/2.f];
  110. [self.view addSubview:pointView3];
  111. [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  113. make.height.mas_equalTo(h_pwd);
  114. make.width.mas_equalTo(w_pwd);
  115. make.top.mas_equalTo(151.f + H_STATE_BAR);
  116. }];
  117. /*下方绘制键盘按钮*/
  118. UIView *bgViewForNumberBoard = [[UIView alloc] init];
  119. [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
  120. CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
  121. CGFloat h_bgViewForNumberBoard = 330.f;
  122. [self.view addSubview:bgViewForNumberBoard];
  123. [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.mas_equalTo(22.f*AUTOSCALE);
  125. make.height.mas_equalTo(h_bgViewForNumberBoard);
  126. make.width.mas_equalTo(w_bgViewForNumberBoard);
  127. make.bottom.mas_equalTo(-70.f);
  128. }];
  129. CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
  130. CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
  131. /*绘制键盘 1~9*/
  132. for (NSInteger nFori = 0; nFori < 9; nFori++) {
  133. CGFloat x_key_btn = (nFori%3)*w_key_btn;
  134. CGFloat y_key_btn = (nFori/3)*h_key_btn;
  135. UIButton *keyBoardBtn = [[UIButton alloc] init];
  136. [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
  137. [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  138. [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  139. [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
  140. [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  141. [bgViewForNumberBoard addSubview:keyBoardBtn];
  142. [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.left.mas_equalTo(x_key_btn);
  144. make.top.mas_equalTo(y_key_btn);
  145. make.width.mas_equalTo(w_key_btn);
  146. make.height.mas_equalTo(h_key_btn);
  147. }];
  148. }
  149. /*删除按钮*/
  150. UIButton *deleteBoardBtn = [[UIButton alloc] init];
  151. [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
  152. [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  153. [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
  154. [bgViewForNumberBoard addSubview:deleteBoardBtn];
  155. [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  156. make.left.mas_equalTo(0);
  157. make.bottom.mas_equalTo(0);
  158. make.width.mas_equalTo(w_key_btn);
  159. make.height.mas_equalTo(h_key_btn);
  160. }];
  161. /*0*/
  162. keyBoardBtn0 = [[UIButton alloc] init];
  163. [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
  164. [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  165. [keyBoardBtn0 setTitleColor:COLOR_PACEHOLDER forState:(UIControlStateDisabled)];
  166. [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  167. [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
  168. [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  169. keyBoardBtn0.enabled = NO;
  170. [bgViewForNumberBoard addSubview:keyBoardBtn0];
  171. [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.left.mas_equalTo(w_key_btn);
  173. make.bottom.mas_equalTo(0);
  174. make.width.mas_equalTo(w_key_btn);
  175. make.height.mas_equalTo(h_key_btn);
  176. }];
  177. /*OK*/
  178. UIButton *keyBoardBtnOK = [[UIButton alloc] init];
  179. [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
  180. [keyBoardBtnOK setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  181. [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
  182. [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
  183. [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
  184. [bgViewForNumberBoard addSubview:keyBoardBtnOK];
  185. [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
  186. make.left.mas_equalTo(2*w_key_btn);
  187. make.bottom.mas_equalTo(0);
  188. make.width.mas_equalTo(w_key_btn);
  189. make.height.mas_equalTo(h_key_btn);
  190. }];
  191. }
  192. - (void)deleteBoardBtnPressed{
  193. if (pwd.length > 0){
  194. NSInteger numberLength = pwd.length;
  195. if (numberLength == 1){
  196. [pointView0 setText:@""];
  197. [pointView0 setBackgroundColor:HWE3E8F1Color];
  198. self->keyBoardBtn0.enabled = NO;
  199. }else if (numberLength == 2){
  200. [pointView1 setText:@""];
  201. [pointView1 setBackgroundColor:HWE3E8F1Color];
  202. }else if (numberLength == 3){
  203. [pointView2 setText:@""];
  204. [pointView2 setBackgroundColor:HWE3E8F1Color];
  205. }else if (numberLength == 4){
  206. [pointView3 setText:@""];
  207. [pointView3 setBackgroundColor:HWE3E8F1Color];
  208. }
  209. pwd = [pwd substringToIndex:numberLength-1];
  210. }
  211. }
  212. - (void)keyBoardBtnOKPressed{
  213. if (pwd.length == 4){
  214. /*进入下一级确认密码*/
  215. ModifyPWDSecondViewController *nextVC = [[ModifyPWDSecondViewController alloc] init];
  216. nextVC.oldPWD = pwd;
  217. [self.navigationController pushViewController:nextVC animated:YES];
  218. }
  219. }
  220. - (void)keyBoardBtnPressed:(id)sender{
  221. UIButton *btn = (UIButton *)sender;
  222. NSString *selectNumberStr = btn.titleLabel.text;
  223. if (pwd.length < 4){
  224. NSInteger numberLength = pwd.length;
  225. if (numberLength == 0){
  226. [pointView0 setText:selectNumberStr];
  227. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  228. [self->pointView0 setBackgroundColor:HW0A132BColor];
  229. self->keyBoardBtn0.enabled = YES;
  230. });
  231. }else if (numberLength == 1){
  232. [pointView1 setText:selectNumberStr];
  233. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  234. [self->pointView1 setBackgroundColor:HW0A132BColor];
  235. });
  236. }else if (numberLength == 2){
  237. [pointView2 setText:selectNumberStr];
  238. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  239. [self->pointView2 setBackgroundColor:HW0A132BColor];
  240. });
  241. }else if (numberLength == 3){
  242. [pointView3 setText:selectNumberStr];
  243. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  244. [self->pointView3 setBackgroundColor:HW0A132BColor];
  245. });
  246. }
  247. pwd = [pwd stringByAppendingString:selectNumberStr];
  248. }
  249. }
  250. /*
  251. #pragma mark - Navigation
  252. // In a storyboard-based application, you will often want to do a little preparation before navigation
  253. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  254. // Get the new view controller using [segue destinationViewController].
  255. // Pass the selected object to the new view controller.
  256. }
  257. */
  258. @end