PasswordView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // PasswordView.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/17.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "PasswordView.h"
  9. #import "UserInputCell.h"
  10. #import <Masonry/Masonry.h>
  11. #import "Header.h"
  12. @interface PasswordView() <UITableViewDelegate,UITableViewDataSource>
  13. @end
  14. @implementation PasswordView
  15. -(instancetype)initWithFrame:(CGRect)frame
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. self.backgroundColor = [UIColor whiteColor];
  20. [self addSubview:self.tbPassWord];
  21. [self addSubview:self.changePwdBtn];
  22. //布局
  23. [self configSubView];
  24. }
  25. return self;
  26. }
  27. #pragma mark - 控件布局
  28. -(void)configSubView
  29. {
  30. [self.tbPassWord mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.top.equalTo(@110);
  32. make.width.equalTo(self).multipliedBy(0.9);
  33. make.height.equalTo(@192);
  34. make.centerX.equalTo(self);
  35. }];
  36. [self.changePwdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self.tbPassWord.mas_bottom).offset(60);
  38. make.width.equalTo(self).multipliedBy(0.9);
  39. make.height.equalTo(@45);
  40. make.centerX.equalTo(self);
  41. }];
  42. }
  43. #pragma mark - button Event
  44. //点击密码修改按钮
  45. -(void)changePwdBtnClicked:(UIButton *)sender
  46. {
  47. if (self.changePwdClicked) {
  48. self.changePwdClicked(self.pwdOldTF.text, self.pwdNewTF.text, self.confrimTF.text);
  49. }
  50. }
  51. //点击空白处隐藏键盘
  52. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  53. {
  54. [self endEditing:YES];
  55. }
  56. #pragma mark - tableViewDataSource/Delegate
  57. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  58. return 4;
  59. }
  60. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  61. return 48;
  62. }
  63. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. UserInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserInputCell"];
  65. switch (indexPath.row) {
  66. case 0:
  67. {
  68. cell.customTitle.text = TS("Device_Name");
  69. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  70. cell.inputTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  71. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  72. cell.inputTextField.text = channel.loginName;
  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.customTitle.adjustsFontSizeToFitWidth = YES;
  101. cell.inputTextField.attributedPlaceholder =[[NSAttributedString alloc]initWithString:TS("PwdInputTip2") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  102. cell.inputTextField.secureTextEntry = 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:12]];
  141. [_changePwdBtn addTarget:self action:@selector(changePwdBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  142. }
  143. return _changePwdBtn;
  144. }
  145. @end