iOS车牌号输入框

研究了ETCP停车软件,感觉这个输入框特别牛,效果很不错的输入框。废话不说了  上代码

下面是点击A B C D 等按钮的Block

- (void)onKeyBoardBtnClock:(UIButton *)button{

    if ([self.delegate respondsToSelector:@selector(addKeyText:)]) {

        [self.delegate addKeyText:button];

    }

这是删除键的Block

- (void)deleteClick{

    if ([self.delegate respondsToSelector:@selector(deleteKey)]) {

        [self.delegate deleteKey];

    }

往右添加的逻辑代码

- (void)addKeyText:(UIButton *)button{

    if (_select == YES) {

        _selectIndex = _selectIndex+1;

    }

    _select = NO;

    UILabel *allLable1 = [self viewWithTag:_selectIndex];

    allLable1.text = button.currentTitle;

    if (allLable1.text.length == 0) {

        

        for (int i = 0; i < 7; i++) {

            UILabel *allLable = [self viewWithTag:100+i];

            if (allLable.tag == _selectIndex) {

                allLable.layer.borderColor = [self colorWithHexString:@"39d5b8"].CGColor;

                allLable.layer.borderWidth = 1;

                if (allLable.tag == 100) {

                    [_keyView.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];

                }else{

                    [_keyView.scrollView setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width, 0) animated:YES];

                }

                

            }else{

                allLable.layer.borderColor = [self colorWithHexString:@"ebebeb"].CGColor;

                allLable.layer.borderWidth = 1;

            }

            

            

        }

        _selectIndex ++;

    }else{

        for (int i = 0; i < 7; i++) {

            UILabel *allLable = [self viewWithTag:100+i];

            if (allLable.tag == _selectIndex+1) {

                

                allLable.layer.borderColor = [self colorWithHexString:@"39d5b8"].CGColor;

                allLable.layer.borderWidth = 1;

                if (allLable.tag == 100) {

                    [_keyView.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];

                }else{

                    [_keyView.scrollView setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width, 0) animated:YES];

                }

                

            }else{

                allLable.layer.borderColor = [self colorWithHexString:@"ebebeb"].CGColor;

                allLable.layer.borderWidth = 1;

            }

            

            

        }

        _selectIndex ++;

    }

    

    

    if (_selectIndex == 99) {

        _selectIndex = 100;

    }

    if (_selectIndex == 107) {

        [UIView animateWithDuration:0.3 animations:^{

            _keyView.hidden = YES;

        } completion:^(BOOL finished) {

            

        }];

    }

    

}

}

}

往左删除的逻辑代码

- (void)deleteKey{

    

    if (_selectIndex == 99) {

        _selectIndex = 100;

    }

    

    

    UILabel *lable = [self viewWithTag:_selectIndex];

    if (lable.text.length == 0) {

        _selectIndex--;

        _select = NO;

        if (_selectIndex == 99) {

            _selectIndex = 100;

        }

        for (int i = 0; i < 7; i++) {

            UILabel *allLable = [self viewWithTag:100+i];

            if (allLable.tag == _selectIndex) {

                

                allLable.layer.borderColor = [self colorWithHexString:@"39d5b8"].CGColor;

                allLable.layer.borderWidth = 1;

                allLable.text = @"";

                if (allLable.tag == 100) {

                    [_keyView.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];

                }else{

                    [_keyView.scrollView setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width, 0) animated:YES];

                }

            }else{

                allLable.layer.borderColor = [self colorWithHexString:@"ebebeb"].CGColor;

                allLable.layer.borderWidth = 1;

            }

            

        }

    }else{

        

        for (int i = 0; i < 7; i++) {

            UILabel *allLable = [self viewWithTag:100+i];

            if (allLable.tag == _selectIndex) {

                

                allLable.layer.borderColor =[self colorWithHexString:@"39d5b8"].CGColor;

                allLable.layer.borderWidth = 1;

                allLable.text = @"";

                if (allLable.tag == 100) {

                    [_keyView.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];

                }else{

                    [_keyView.scrollView setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width, 0) animated:YES];

                }

            }else{

                allLable.layer.borderColor = [self colorWithHexString:@"ebebeb"].CGColor;

                allLable.layer.borderWidth = 1;

            }

            

        }

        _select = YES;

        _selectIndex--;

    }

    

    if (_selectIndex == 100) {

        _selectIndex = 100;

    }

   

}

技术其实就是边框颜色切换,在有View封装的键盘,主要还是算法  https://github.com/caoliangliang19/textField  这是下载地址 写了好长时间  好多都忘了

 

posted @ 2017-08-14 14:56  曹亮亮  阅读(1024)  评论(0)    收藏  举报