ChangePasswordView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // ChangePasswordView.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/10/30.
  6. // Copyright © 2018年 wujiangbo. All rights reserved.
  7. //
  8. #import "ChangePasswordView.h"
  9. #import "UserInputCell.h"
  10. #import <Masonry/Masonry.h>
  11. #import "LoginShowControl.h"
  12. #import "Header.h"
  13. @interface ChangePasswordView()<UITableViewDelegate,UITableViewDataSource>
  14. @end
  15. @implementation ChangePasswordView
  16. -(instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.backgroundColor = [UIColor whiteColor];
  21. [self addSubview:self.tbPassWord];
  22. [self addSubview:self.changePwdBtn];
  23. //布局
  24. [self configSubView];
  25. }
  26. return self;
  27. }
  28. #pragma mark - 控件布局
  29. -(void)configSubView
  30. {
  31. [self.tbPassWord mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.equalTo(@110);
  33. make.width.equalTo(self).multipliedBy(0.9);
  34. make.height.equalTo(@192);
  35. make.centerX.equalTo(self);
  36. }];
  37. [self.changePwdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.tbPassWord.mas_bottom).offset(60);
  39. make.width.equalTo(self).multipliedBy(0.9);
  40. make.height.equalTo(@45);
  41. make.centerX.equalTo(self);
  42. }];
  43. }
  44. #pragma mark - button Event
  45. //点击密码修改按钮
  46. -(void)changePwdBtnClicked:(UIButton *)sender
  47. {
  48. if (self.changePwdBtnClicked) {
  49. self.changePwdBtnClicked([[LoginShowControl getInstance] getLoginUserName],self.pwdOldTF.text, self.pwdNewTF.text, self.confrimTF.text);
  50. }
  51. }
  52. //点击空白处隐藏键盘
  53. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  54. {
  55. [self endEditing:YES];
  56. }
  57. #pragma mark - tableViewDataSource/Delegate
  58. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  59. return 4;
  60. }
  61. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  62. return 48;
  63. }
  64. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  65. UserInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserInputCell"];
  66. switch (indexPath.row) {
  67. case 0:
  68. {
  69. cell.customTitle.text = TS("UserName");
  70. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  71. cell.inputTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  72. cell.inputTextField.text = [[LoginShowControl getInstance] getLoginUserName];
  73. cell.inputTextField.enabled = NO;
  74. cell.toggleBtn.hidden = YES;
  75. }
  76. break;
  77. case 1:
  78. {
  79. cell.customTitle.text = TS("Old_Password");
  80. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  81. cell.inputTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:TS("Old_Password") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  82. self.pwdOldTF = cell.inputTextField;
  83. cell.toggleBtn.hidden = YES;
  84. }
  85. break;
  86. case 2:
  87. {
  88. cell.customTitle.text = TS("New_Password");
  89. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  90. cell.inputTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:TS("PwdInputTip") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  91. cell.inputTextField.secureTextEntry = YES;
  92. self.pwdNewTF = cell.inputTextField;
  93. cell.toggleBtn.hidden = NO;
  94. [cell.toggleBtn addTarget:self action:@selector(showPassword) forControlEvents:UIControlEventTouchUpInside];
  95. }
  96. break;
  97. default:
  98. {
  99. cell.customTitle.text = TS("New_Password");
  100. cell.inputTextField.attributedPlaceholder =[[NSAttributedString alloc]initWithString:TS("PwdInputTip2") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  101. cell.inputTextField.secureTextEntry = YES;
  102. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  103. self.confrimTF = cell.inputTextField;
  104. cell.toggleBtn.hidden = NO;
  105. [cell.toggleBtn addTarget:self action:@selector(showPassword) forControlEvents:UIControlEventTouchUpInside];
  106. }
  107. break;
  108. }
  109. return cell;
  110. }
  111. //显示密码
  112. -(void)showPassword
  113. {
  114. self.pwdNewTF.secureTextEntry = !self.pwdNewTF.secureTextEntry;
  115. UserInputCell *cell1 = [self.tbPassWord cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
  116. cell1.toggleBtn.selected = !cell1.toggleBtn.selected;
  117. self.confrimTF.secureTextEntry = !self.confrimTF.secureTextEntry;
  118. UserInputCell *cell2 = [self.tbPassWord cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
  119. cell2.toggleBtn.selected = !cell2.toggleBtn.selected;
  120. }
  121. #pragma mark - LazyLoad
  122. -(UITableView *)tbPassWord {
  123. if (!_tbPassWord) {
  124. _tbPassWord = [[UITableView alloc] init];
  125. _tbPassWord.delegate = self;
  126. _tbPassWord.dataSource = self;
  127. _tbPassWord.scrollEnabled = NO;
  128. _tbPassWord.layer.cornerRadius = 4;
  129. _tbPassWord.allowsSelection = NO;
  130. [_tbPassWord registerClass:[UserInputCell class] forCellReuseIdentifier:@"UserInputCell"];
  131. }
  132. return _tbPassWord;
  133. }
  134. -(UIButton *)changePwdBtn
  135. {
  136. if (!_changePwdBtn) {
  137. _changePwdBtn = [[UIButton alloc] init];
  138. [_changePwdBtn setTitle:TS("Modify_pwd") forState:UIControlStateNormal];
  139. [_changePwdBtn setBackgroundColor:GlobalMainColor];
  140. [_changePwdBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  141. [_changePwdBtn addTarget:self action:@selector(changePwdBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  142. }
  143. return _changePwdBtn;
  144. }
  145. @end