iOS 仿写 支付宝 验证码输入
2018-05-28 本文已影响121人
目染江夏
简单原理就是 用textfeild 输入 ,隐藏掉textfeild;创建六个label 显示六个字符,再加上判断处理。把功能做好了没有做封装,有需要可以私密我。
代码如下:
_strArr = [NSMutableArray array];
_inputBgView = [[UIView alloc]initWithFrame:CGRectMake(40, 60, 145, 30)];
[self.view addSubview:_inputBgView];
_labArr = [NSMutableArray new];
for (NSInteger index = 0; index < 6; index ++) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake( (5 + 20) * index, 0, 20, 20)];
label.backgroundColor = [UIColor redColor];
label.textColor = [UIColor yellowColor];
label.textAlignment = NSTextAlignmentCenter;
[self.inputBgView addSubview:label];
[_labArr addObject:label];
}
_cyTextField = [[CYTextField alloc]initWithFrame:_inputBgView.bounds];
_cyTextField.isClosePaste = YES;
// UITextField关闭系统自动联想和首字母大写功能
[_cyTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
[_cyTextField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
_cyTextField.keyboardType = UIKeyboardTypeNumberPad;
_cyTextField.clearButtonMode = UITextFieldViewModeNever;
_cyTextField.font = [UIFont systemFontOfSize:14];
_cyTextField.delegate = self;
_cyTextField.tintColor = [UIColor clearColor];
_cyTextField.backgroundColor = [UIColor clearColor];
_cyTextField.placeholder = @"";
_cyTextField.textColor = [UIColor clearColor];
[_cyTextField addTarget:self action:@selector(valeChange:) forControlEvents:UIControlEventEditingChanged];
[self.inputBgView addSubview:_cyTextField];