EamilTFmatchV.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // EamilTFmatchV.m
  3. // westkissMob
  4. //
  5. // Created by 王猛 on 2022/9/7.
  6. //
  7. #import "EamilTFmatchV.h"
  8. @interface EamilTFmatchV ()<
  9. UITextFieldDelegate,
  10. UITableViewDelegate,
  11. UITableViewDataSource
  12. >
  13. @property (nonatomic, strong) UILabel *xxx_emialLab;
  14. @property(nonatomic,strong)UITableView *table;
  15. @property(nonatomic,strong)NSArray * hzArr;//后缀数组
  16. @property(nonatomic,strong)NSMutableArray * ppMuArr;//匹配中的数组
  17. @end
  18. @implementation EamilTFmatchV
  19. +(CGFloat)xxx_emailMatchVheight{
  20. return 120+50;
  21. }
  22. - (void)tt_configDefault{
  23. _hzArr = @[@"@gmail.com",@"@hotmall.com",@"@yahoo.com",@"@icloud.com",@"@outlook.com",@"@aolp.com",@"@zoho.com",@"@inbox.com",@"@mail.com"];
  24. _ppMuArr = [[NSMutableArray alloc]init];
  25. }
  26. - (void)tt_setupViews{
  27. [self addSubview:self.xxx_emailTF];
  28. [self addSubview:self.xxx_emialLab];
  29. [self addSubview:self.table];
  30. }
  31. #pragma mark - **************** UITextFieldDelegate ****************
  32. -(void)textFieldDidEndEditing:(UITextField *)textField{
  33. NSLog(@"-------%@",self.xxx_emailTF.text);
  34. if (textField == self.xxx_emailTF) {
  35. if (![Current_normalTool xxx_isValidateEmail:self.xxx_emailTF.text]) {
  36. self.xxx_emialLab.hidden = NO;
  37. }else{
  38. self.xxx_emialLab.hidden = YES;
  39. }
  40. self.table.hidden = YES;
  41. self.mj_h = 50;
  42. }
  43. }
  44. ///文本框字符变化时
  45. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  46. self.table.hidden = NO;
  47. self.mj_h = 120+50;
  48. if (!range.length){
  49. if ([string isEqualToString:@"@"] || [textField.text containsString:@"@"]) {
  50. self.table.hidden = YES;
  51. self.mj_h = 50;
  52. }else{
  53. _ppMuArr = [[NSMutableArray alloc]init];
  54. [_hzArr enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL * _Nonnull stop) {
  55. NSString * ppString = [textField.text stringByAppendingString:[NSString stringWithFormat:@"%@%@",string,obj]];
  56. [self.ppMuArr addObject:ppString];
  57. }];
  58. }
  59. }else{
  60. _ppMuArr = [[NSMutableArray alloc]init];
  61. if (textField.text.length - 1 == 0 || [textField.text containsString:@"@"]) {
  62. self.table.hidden = YES;
  63. self.mj_h = 50;
  64. }else{
  65. [_hzArr enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL * _Nonnull stop) {
  66. NSString *matchStr = [textField.text substringToIndex:(textField.text.length - 1)];
  67. NSString * ppString = [NSString stringWithFormat:@"%@%@",matchStr,obj];
  68. [self.ppMuArr addObject:ppString];
  69. }];
  70. }
  71. }
  72. [self.table reloadData];
  73. return YES;
  74. }
  75. - (BOOL)textFieldShouldClear:(UITextField *)textField{
  76. self.table.hidden = YES;
  77. self.mj_h = 50;
  78. return YES;
  79. }
  80. // 进入编辑状态是否需要匹配
  81. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  82. if (textField.text.length != 0){
  83. self.table.hidden = NO;
  84. self.mj_h = 120+50;
  85. [self.table reloadData];
  86. }
  87. return YES;
  88. }
  89. #pragma mark dataSource method and delegate method
  90. - (NSInteger)tableView:(UITableView*)table numberOfRowsInSection:(NSInteger)section{
  91. return self.ppMuArr.count;
  92. }
  93. - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
  94. static NSString * cellIdentifier = @"cell";
  95. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  96. if (!cell) {
  97. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  98. }
  99. cell.textLabel.text = self.ppMuArr[indexPath.row];
  100. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  101. cell.textLabel.font = [UIFont systemFontOfSize:14];
  102. return cell;
  103. }
  104. - (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
  105. return 30;
  106. }
  107. - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
  108. // 将完整email填入输入框
  109. self.xxx_emailTF.text = self.ppMuArr[indexPath.row];
  110. self.table.hidden = YES;
  111. self.mj_h = 50;
  112. if (![Current_normalTool xxx_isValidateEmail:self.xxx_emailTF.text]) {
  113. self.xxx_emialLab.hidden = NO;
  114. }else{
  115. self.xxx_emialLab.hidden = YES;
  116. }
  117. }
  118. -(TT_CustonTF *)xxx_emailTF{
  119. if (!_xxx_emailTF) {
  120. _xxx_emailTF = [TT_ControlTool FTT_ControlToolUITextFieldFrame:CGRectMake(20, 0, KScreenWidth-40, 50)
  121. PlaceHolder:@"* EMAIl"
  122. andLifImage:nil
  123. AndRightImage:nil
  124. LiftImageFrame:CGRectZero
  125. RightImageFrame:CGRectZero
  126. AndTag:0
  127. AndKeyboardType:UIKeyboardTypeDefault
  128. clearButtonMode:UITextFieldViewModeAlways
  129. AndReturnKeyType:UIReturnKeyDone
  130. masksToBounds:YES
  131. conrenRadius:4
  132. BorderColor:[UIColor colorWithHexString:@"#000000"]
  133. BorderWidth:1];
  134. _xxx_emailTF.delegate = self;
  135. }
  136. return _xxx_emailTF;
  137. }
  138. -(UILabel *)xxx_emialLab{
  139. if (!_xxx_emialLab) {
  140. _xxx_emialLab = [UILabel new];
  141. _xxx_emialLab.frame = CGRectMake(20, 50, KScreenWidth-40, 20);
  142. _xxx_emialLab.textColor = [UIColor colorWithHexString:@"#bf1221"];
  143. _xxx_emialLab.textAlignment = NSTextAlignmentCenter;
  144. _xxx_emialLab.backgroundColor= [UIColor clearColor];
  145. _xxx_emialLab.text = @"* Please prvide an email address.";
  146. _xxx_emialLab.font = [UIFont systemFontOfSize:12];
  147. _xxx_emialLab.hidden = YES;
  148. }
  149. return _xxx_emialLab;
  150. }
  151. -(UITableView *)table{
  152. if (!_table) {
  153. _table = [[UITableView alloc] initWithFrame:CGRectMake(20,50,KScreenWidth-40,120)];
  154. _table.separatorStyle = UITableViewCellSeparatorStyleNone;
  155. _table.dataSource=self;
  156. _table.delegate=self;
  157. _table.hidden = YES;
  158. self.mj_h = 50;
  159. }
  160. return _table;
  161. }
  162. @end