RegisterView.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. //
  2. // RegisterView.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/10/27.
  6. // Copyright © 2018年 wujiangbo. All rights reserved.
  7. //
  8. #import "RegisterView.h"
  9. #import "UserInputCell.h"
  10. #import <Masonry/Masonry.h>
  11. #import "Header.h"
  12. @interface RegisterView()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  13. @property (nonatomic, assign) int seqNum;
  14. @end
  15. @implementation RegisterView
  16. -(instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.backgroundColor = [UIColor whiteColor];
  21. [self addSubview:self.tbSettings];
  22. [self addSubview:self.errorTipLabel];
  23. [self addSubview:self.registerBtn];
  24. [self addSubview:self.phoneTF];
  25. [self addSubview:self.codeTF];
  26. [self addSubview:self.getCodeBtn];
  27. [self addSubview:self.jumpBtn];
  28. [self addSubview:self.btnSelector];
  29. [self addSubview:self.lbDescription];
  30. [self addSubview:self.btnPrivacy];
  31. //布局
  32. [self configSubView];
  33. }
  34. return self;
  35. }
  36. #pragma mark - 控件布局
  37. -(void)configSubView
  38. {
  39. [self.tbSettings mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(@110);
  41. make.width.equalTo(self).multipliedBy(0.9);
  42. make.height.equalTo(@144);
  43. make.centerX.equalTo(self);
  44. }];
  45. [self.errorTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.top.equalTo(@70);
  47. make.centerX.equalTo(self);
  48. make.width.equalTo(self).multipliedBy(0.9);
  49. make.height.equalTo(@40);
  50. }];
  51. [self.phoneTF mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.equalTo(self.tbSettings);
  53. make.width.equalTo(self).offset(-10).multipliedBy(0.67);
  54. make.height.equalTo(@45);
  55. make.top.equalTo(self.tbSettings.mas_bottom).offset(20);
  56. }];
  57. [self.codeTF mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.equalTo(self.tbSettings);
  59. make.width.equalTo(self).offset(-10).multipliedBy(0.67);
  60. make.height.equalTo(@45);
  61. make.top.equalTo(self.tbSettings.mas_bottom).offset(20);
  62. }];
  63. [self.getCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.right.equalTo(self.tbSettings);
  65. make.width.equalTo(self).offset(-10).multipliedBy(0.33);
  66. make.height.equalTo(@45);
  67. make.top.equalTo(self.phoneTF);
  68. }];
  69. [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.top.equalTo(self.phoneTF.mas_bottom).offset(50);
  71. make.width.equalTo(self).multipliedBy(0.9);
  72. make.height.equalTo(@45);
  73. make.centerX.equalTo(self);
  74. }];
  75. [self.jumpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.top.equalTo(self.phoneTF.mas_bottom).offset(10);
  77. make.width.equalTo(self).multipliedBy(0.9);
  78. make.centerX.equalTo(self);
  79. make.height.equalTo(@25);
  80. }];
  81. [self.btnSelector mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(self.registerBtn.mas_left);
  83. make.width.equalTo(@40);
  84. make.height.equalTo(@40);
  85. make.top.equalTo(self.registerBtn.mas_bottom).offset(20);
  86. }];
  87. [self.lbDescription mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(self.btnSelector.mas_right);
  89. make.width.equalTo(@100);
  90. make.height.equalTo(@40);
  91. make.centerY.equalTo(self.btnSelector.mas_centerY);
  92. }];
  93. [self.btnPrivacy mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.equalTo(self.lbDescription.mas_right);
  95. make.width.equalTo(@150);
  96. make.height.equalTo(@40);
  97. make.centerY.equalTo(self.btnSelector.mas_centerY);
  98. }];
  99. }
  100. //密码显示
  101. -(void)showPassword
  102. {
  103. self.pwdTF.secureTextEntry = !self.pwdTF.secureTextEntry;
  104. UserInputCell *cell1 = [self.tbSettings cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
  105. cell1.toggleBtn.selected = !cell1.toggleBtn.selected;
  106. self.confrimTF.secureTextEntry = !self.confrimTF.secureTextEntry;
  107. UserInputCell *cell2 = [self.tbSettings cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
  108. cell2.toggleBtn.selected = !cell2.toggleBtn.selected;
  109. }
  110. #pragma mark - tableViewDataSource/Delegate
  111. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  112. return 3;
  113. }
  114. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  115. return 1;
  116. }
  117. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  118. return 48;
  119. }
  120. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  121. UserInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserInputCell"];
  122. switch (indexPath.row) {
  123. case 0:
  124. {
  125. cell.customTitle.text = TS("username");
  126. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  127. cell.inputTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:TS("UserInputTip") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  128. cell.inputTextField.delegate = self;
  129. cell.inputTextField.text = [[NSUserDefaults standardUserDefaults]stringForKey:@"registerName"];
  130. self.userNameTF = cell.inputTextField;
  131. [self.userNameTF addTarget:self action:@selector(textFieldTextDidChange:) forControlEvents:UIControlEventEditingChanged];
  132. cell.toggleBtn.hidden = YES;
  133. }
  134. break;
  135. case 1:
  136. {
  137. cell.customTitle.text = TS("password");
  138. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  139. cell.inputTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:TS("PwdInputTip") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  140. cell.inputTextField.secureTextEntry = YES;
  141. cell.inputTextField.text = [[NSUserDefaults standardUserDefaults]stringForKey:@"registerPwd"];
  142. self.pwdTF = cell.inputTextField;
  143. cell.toggleBtn.hidden = NO;
  144. [cell.toggleBtn addTarget:self action:@selector(showPassword) forControlEvents:UIControlEventTouchUpInside];
  145. }
  146. break;
  147. default:
  148. {
  149. cell.customTitle.text = TS("confirm_psd");
  150. cell.inputTextField.attributedPlaceholder =[[NSAttributedString alloc]initWithString:TS("PwdInputTip2") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
  151. cell.inputTextField.secureTextEntry = YES;
  152. cell.inputTextField.text = [[NSUserDefaults standardUserDefaults]stringForKey:@"registerConfirm"];
  153. cell.customTitle.adjustsFontSizeToFitWidth = YES;
  154. self.confrimTF = cell.inputTextField;
  155. cell.toggleBtn.hidden = NO;
  156. [cell.toggleBtn addTarget:self action:@selector(showPassword) forControlEvents:UIControlEventTouchUpInside];
  157. }
  158. break;
  159. }
  160. return cell;
  161. }
  162. #pragma mark - UITextFieldDelegate
  163. -(void)textFieldTextDidChange:(UITextField *)sender {
  164. self.errorTipLabel.text = @"";
  165. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  166. }
  167. #pragma mark - button event
  168. -(void)registerBtnClicked:(UIButton *)sender
  169. {
  170. if (self.btnSelector.selected) {
  171. [SVProgressHUD showErrorWithStatus:TS("Please_agree_privacy_policy")];
  172. return;
  173. }
  174. if (self.registerBtnClicked) {
  175. self.registerBtnClicked(self.userNameTF.text, self.pwdTF.text, self.confrimTF.text, self.phoneTF.text, self.codeTF.text);
  176. }
  177. }
  178. -(void)getCodeBtnClicked:(UIButton *)sender
  179. {
  180. self.jumpBtn.hidden = YES;
  181. if (self.getCodeBtnClicked) {
  182. self.getCodeBtnClicked(self.phoneTF.text);
  183. }
  184. }
  185. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  186. {
  187. [self endEditing:YES];
  188. }
  189. -(void)jumpBtnClicked:(UIButton *)sender
  190. {
  191. sender.selected = !sender.selected;
  192. }
  193. -(void)btnSelectorClicked:(UIButton *)sender
  194. {
  195. sender.selected = !sender.selected;
  196. }
  197. -(void)btnPrivacyClicked:(UIButton *)sender
  198. {
  199. if (self.btnPrivacyBtnClicked) {
  200. self.btnPrivacyBtnClicked();
  201. }
  202. }
  203. #pragma mark - lazyLoad
  204. -(UITableView *)tbSettings {
  205. if (!_tbSettings) {
  206. _tbSettings = [[UITableView alloc] init];
  207. _tbSettings.delegate = self;
  208. _tbSettings.dataSource = self;
  209. _tbSettings.scrollEnabled = NO;
  210. _tbSettings.layer.cornerRadius = 4;
  211. _tbSettings.allowsSelection = NO;
  212. [_tbSettings registerClass:[UserInputCell class] forCellReuseIdentifier:@"UserInputCell"];
  213. }
  214. return _tbSettings;
  215. }
  216. -(UILabel *)errorTipLabel
  217. {
  218. if (!_errorTipLabel) {
  219. _errorTipLabel = [[UILabel alloc] init];
  220. _errorTipLabel.text = @"";
  221. _errorTipLabel.textAlignment = NSTextAlignmentCenter;
  222. _errorTipLabel.textColor = [UIColor redColor];
  223. _errorTipLabel.numberOfLines = 0;
  224. _errorTipLabel.font = [UIFont systemFontOfSize:12];
  225. }
  226. return _errorTipLabel;
  227. }
  228. -(UITextField *)phoneTF
  229. {
  230. if (!_phoneTF) {
  231. _phoneTF = [[UITextField alloc] init];
  232. _phoneTF.placeholder = TS("phone_num");
  233. _phoneTF.backgroundColor = [UIColor whiteColor];
  234. _phoneTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
  235. _phoneTF.leftViewMode = UITextFieldViewModeAlways;
  236. }
  237. return _phoneTF;
  238. }
  239. -(UITextField *)codeTF
  240. {
  241. if (!_codeTF) {
  242. _codeTF = [[UITextField alloc] init];
  243. _codeTF.placeholder = TS("input_code");
  244. _codeTF.hidden = YES;
  245. _codeTF.backgroundColor = [UIColor whiteColor];
  246. }
  247. return _codeTF;
  248. }
  249. -(UIButton *)getCodeBtn
  250. {
  251. if (!_getCodeBtn) {
  252. _getCodeBtn = [[UIButton alloc] init];
  253. _getCodeBtn.layer.cornerRadius = 5;
  254. [_getCodeBtn setTitle:TS("get_code") forState:UIControlStateNormal];
  255. [_getCodeBtn setBackgroundColor:GlobalMainColor];
  256. [_getCodeBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  257. [_getCodeBtn addTarget:self action:@selector(getCodeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  258. }
  259. return _getCodeBtn;
  260. }
  261. -(UIButton *)registerBtn
  262. {
  263. if (!_registerBtn) {
  264. _registerBtn = [[UIButton alloc] init];
  265. [_registerBtn setTitle:TS("register") forState:UIControlStateNormal];
  266. [_registerBtn setBackgroundColor:GlobalMainColor];
  267. [_registerBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  268. [_registerBtn addTarget:self action:@selector(registerBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  269. }
  270. return _registerBtn;
  271. }
  272. -(UIButton *)btnSelector
  273. {
  274. if (!_btnSelector) {
  275. _btnSelector = [[UIButton alloc] init];
  276. [_btnSelector setImage:[UIImage imageNamed:@"sel.png"] forState:UIControlStateNormal];
  277. [_btnSelector setImage:[UIImage imageNamed:@"nor.png"] forState:UIControlStateSelected];
  278. [_btnSelector addTarget:self action:@selector(btnSelectorClicked:) forControlEvents:UIControlEventTouchUpInside];
  279. [_btnSelector setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
  280. }
  281. return _btnSelector;
  282. }
  283. -(UILabel *)lbDescription
  284. {
  285. if (!_lbDescription) {
  286. _lbDescription = [[UILabel alloc] init];
  287. [_lbDescription setText:TS("I_Have_Agreed")];
  288. _lbDescription.font = [UIFont systemFontOfSize:13];
  289. }
  290. return _lbDescription;
  291. }
  292. -(UIButton *)btnPrivacy
  293. {
  294. if (!_btnPrivacy) {
  295. _btnPrivacy = [[UIButton alloc] init];
  296. [_btnPrivacy setTitle:TS("Privacy_Policy") forState:UIControlStateNormal];
  297. [_btnPrivacy setTitleColor:GlobalMainColor forState:UIControlStateNormal];
  298. [_btnPrivacy setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
  299. _btnPrivacy.titleLabel.font = [UIFont systemFontOfSize:12];
  300. [_btnPrivacy addTarget:self action:@selector(btnPrivacyClicked:) forControlEvents:UIControlEventTouchUpInside];
  301. }
  302. return _btnPrivacy;
  303. }
  304. -(UIButton *)jumpBtn
  305. {
  306. if (!_jumpBtn) {
  307. _jumpBtn = [[UIButton alloc] init];
  308. _jumpBtn.layer.cornerRadius = 5;
  309. _jumpBtn.hidden = YES;
  310. _jumpBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  311. [_jumpBtn setImage:[UIImage imageNamed:@"nor.png"] forState:UIControlStateNormal];
  312. [_jumpBtn setImage:[UIImage imageNamed:@"sel.png"] forState:UIControlStateSelected];
  313. [_jumpBtn setTitle:TS("Jump_RegCode") forState:UIControlStateNormal];
  314. [_jumpBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
  315. [_jumpBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  316. [_jumpBtn addTarget:self action:@selector(jumpBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  317. }
  318. return _jumpBtn;
  319. }
  320. @end