123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- //
- // EamilTFmatchV.m
- // westkissMob
- //
- // Created by 王猛 on 2022/9/7.
- //
- #import "EamilTFmatchV.h"
- @interface EamilTFmatchV ()<
- UITextFieldDelegate,
- UITableViewDelegate,
- UITableViewDataSource
- >
- @property (nonatomic, strong) UILabel *xxx_emialLab;
- @property(nonatomic,strong)UITableView *table;
- @property(nonatomic,strong)NSArray * hzArr;//后缀数组
- @property(nonatomic,strong)NSMutableArray * ppMuArr;//匹配中的数组
- @end
- @implementation EamilTFmatchV
- +(CGFloat)xxx_emailMatchVheight{
- return 120+50;
- }
- - (void)tt_configDefault{
- _hzArr = @[@"@gmail.com",@"@hotmall.com",@"@yahoo.com",@"@icloud.com",@"@outlook.com",@"@aolp.com",@"@zoho.com",@"@inbox.com",@"@mail.com"];
- _ppMuArr = [[NSMutableArray alloc]init];
- }
- - (void)tt_setupViews{
- [self addSubview:self.xxx_emailTF];
- [self addSubview:self.xxx_emialLab];
- [self addSubview:self.table];
- }
- #pragma mark - **************** UITextFieldDelegate ****************
- -(void)textFieldDidEndEditing:(UITextField *)textField{
- NSLog(@"-------%@",self.xxx_emailTF.text);
- if (textField == self.xxx_emailTF) {
- if (![Current_normalTool xxx_isValidateEmail:self.xxx_emailTF.text]) {
- self.xxx_emialLab.hidden = NO;
- }else{
- self.xxx_emialLab.hidden = YES;
- }
- self.table.hidden = YES;
- self.mj_h = 50;
- }
- }
- ///文本框字符变化时
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
- self.table.hidden = NO;
- self.mj_h = 120+50;
- if (!range.length){
- if ([string isEqualToString:@"@"] || [textField.text containsString:@"@"]) {
- self.table.hidden = YES;
- self.mj_h = 50;
- }else{
- _ppMuArr = [[NSMutableArray alloc]init];
- [_hzArr enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSString * ppString = [textField.text stringByAppendingString:[NSString stringWithFormat:@"%@%@",string,obj]];
- [self.ppMuArr addObject:ppString];
- }];
- }
- }else{
- _ppMuArr = [[NSMutableArray alloc]init];
- if (textField.text.length - 1 == 0 || [textField.text containsString:@"@"]) {
- self.table.hidden = YES;
- self.mj_h = 50;
- }else{
- [_hzArr enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSString *matchStr = [textField.text substringToIndex:(textField.text.length - 1)];
- NSString * ppString = [NSString stringWithFormat:@"%@%@",matchStr,obj];
- [self.ppMuArr addObject:ppString];
- }];
- }
- }
- [self.table reloadData];
- return YES;
- }
- - (BOOL)textFieldShouldClear:(UITextField *)textField{
- self.table.hidden = YES;
- self.mj_h = 50;
- return YES;
- }
- // 进入编辑状态是否需要匹配
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
- if (textField.text.length != 0){
- self.table.hidden = NO;
- self.mj_h = 120+50;
- [self.table reloadData];
- }
- return YES;
- }
- #pragma mark dataSource method and delegate method
- - (NSInteger)tableView:(UITableView*)table numberOfRowsInSection:(NSInteger)section{
- return self.ppMuArr.count;
- }
- - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
- static NSString * cellIdentifier = @"cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- }
-
- cell.textLabel.text = self.ppMuArr[indexPath.row];
- cell.textLabel.textAlignment = NSTextAlignmentCenter;
- cell.textLabel.font = [UIFont systemFontOfSize:14];
- return cell;
- }
- - (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
- return 30;
- }
- - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
- // 将完整email填入输入框
- self.xxx_emailTF.text = self.ppMuArr[indexPath.row];
- self.table.hidden = YES;
- self.mj_h = 50;
- if (![Current_normalTool xxx_isValidateEmail:self.xxx_emailTF.text]) {
- self.xxx_emialLab.hidden = NO;
- }else{
- self.xxx_emialLab.hidden = YES;
- }
- }
- -(TT_CustonTF *)xxx_emailTF{
- if (!_xxx_emailTF) {
- _xxx_emailTF = [TT_ControlTool FTT_ControlToolUITextFieldFrame:CGRectMake(20, 0, KScreenWidth-40, 50)
- PlaceHolder:@"* EMAIl"
- andLifImage:nil
- AndRightImage:nil
- LiftImageFrame:CGRectZero
- RightImageFrame:CGRectZero
- AndTag:0
- AndKeyboardType:UIKeyboardTypeDefault
- clearButtonMode:UITextFieldViewModeAlways
- AndReturnKeyType:UIReturnKeyDone
- masksToBounds:YES
- conrenRadius:4
- BorderColor:[UIColor colorWithHexString:@"#000000"]
- BorderWidth:1];
- _xxx_emailTF.delegate = self;
- }
- return _xxx_emailTF;
- }
- -(UILabel *)xxx_emialLab{
- if (!_xxx_emialLab) {
- _xxx_emialLab = [UILabel new];
- _xxx_emialLab.frame = CGRectMake(20, 50, KScreenWidth-40, 20);
- _xxx_emialLab.textColor = [UIColor colorWithHexString:@"#bf1221"];
- _xxx_emialLab.textAlignment = NSTextAlignmentCenter;
- _xxx_emialLab.backgroundColor= [UIColor clearColor];
- _xxx_emialLab.text = @"* Please prvide an email address.";
- _xxx_emialLab.font = [UIFont systemFontOfSize:12];
- _xxx_emialLab.hidden = YES;
- }
- return _xxx_emialLab;
- }
- -(UITableView *)table{
- if (!_table) {
- _table = [[UITableView alloc] initWithFrame:CGRectMake(20,50,KScreenWidth-40,120)];
- _table.separatorStyle = UITableViewCellSeparatorStyleNone;
- _table.dataSource=self;
- _table.delegate=self;
- _table.hidden = YES;
- self.mj_h = 50;
- }
- return _table;
- }
- @end
|