diff --git a/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.h b/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.h index 102ee8a..75a127e 100644 --- a/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.h +++ b/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.h @@ -18,6 +18,8 @@ @property(nonatomic,assign)CGFloat borderWidth;//格子的border值 +@property(nonatomic,assign)CGFloat cornerRadius;//圆角 + @property(nonatomic,assign)BOOL lineStyle;//横线样式 @@ -27,6 +29,9 @@ @property (nonatomic, strong)UIColor *selectedColor;//选中颜色 +@property (nonatomic, strong)UIColor *textFieldBackgroundColor;//格子背景颜色 + + @property (nonatomic, strong)NSMutableArray *textFieldArray;//放textField的array用于在外面好取消键盘 @end diff --git a/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.m b/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.m index c3f0f9b..a731964 100644 --- a/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.m +++ b/PZXVerificationCodeTextField/Sources/PZXVerificationCodeTextField-OC/PZXVerificationCodeView.m @@ -24,9 +24,11 @@ - (instancetype)initWithFrame:(CGRect)frame self.VerificationCodeNum = 4;//默认4位 self.Spacing = 0;//默认间距为0 self.lineStyle = false; //默认是格子样式 + self.textFieldBackgroundColor = [UIColor clearColor]; self.selectedColor = [UIColor cyanColor]; self.deselectColor = [UIColor redColor]; //默认边框颜色 self.borderWidth = 1; + self.cornerRadius = 0; [self setView]; //绘制界面 @@ -63,7 +65,8 @@ -(void)setView { for (int i = 0; i < self.VerificationCodeNum; i++) { // Create the text field PZXVerificationTextField *tf = [[PZXVerificationTextField alloc] initWithFrame:CGRectMake(i * (self.frame.size.width / self.VerificationCodeNum) + _Spacing / 2, 0, textFieldWidth, self.frame.size.height)]; - tf.backgroundColor = [UIColor clearColor]; + tf.backgroundColor = self.textFieldBackgroundColor; + tf.layer.cornerRadius = self.cornerRadius; tf.pzx_delegate = self; tf.keyboardType = UIKeyboardTypeNumberPad; tf.textColor = [UIColor blackColor]; diff --git a/PZXVerificationCodeTextField/ViewController.m b/PZXVerificationCodeTextField/ViewController.m index 8796b7a..7e01472 100644 --- a/PZXVerificationCodeTextField/ViewController.m +++ b/PZXVerificationCodeTextField/ViewController.m @@ -16,6 +16,9 @@ @interface ViewController () @property(nonatomic,strong)PZXVerificationCodeView *SpacingView; +@property(nonatomic,strong)PZXVerificationCodeView *grayView; + + @property(nonatomic,strong)UITextField *TF; - (IBAction)changeButtonPressed:(UIButton *)sender; - (IBAction)outButtonPressed:(UIButton *)sender; @@ -54,7 +57,19 @@ - (void)viewDidLoad { [self.view addSubview:_SpacingView]; - _bottomLineInputView = [[PZXVerificationCodeView alloc]initWithFrame:CGRectMake(16, 300, self.view.frame.size.width - 32, 60)]; + _grayView = [[PZXVerificationCodeView alloc]initWithFrame:CGRectMake(0, 300, self.view.frame.size.width, 60)]; + _grayView.selectedColor = [UIColor clearColor]; + _grayView.deselectColor = [UIColor clearColor]; + _grayView.textFieldBackgroundColor = [UIColor groupTableViewBackgroundColor]; + _grayView.borderWidth = 0; + _grayView.cornerRadius = 6; + _grayView.VerificationCodeNum = 6; + // _pzxView.isSecure = YES;//密文 + _grayView.Spacing = 6;//每个格子间距属性 + [self.view addSubview:_grayView]; + + + _bottomLineInputView = [[PZXVerificationCodeView alloc]initWithFrame:CGRectMake(16, 400, self.view.frame.size.width - 32, 60)]; _bottomLineInputView.selectedColor = [UIColor blackColor]; _bottomLineInputView.deselectColor = [UIColor lightGrayColor]; @@ -71,10 +86,11 @@ - (void)viewDidLoad { [NSLayoutConstraint activateConstraints:@[ [_codeInputView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], - [_codeInputView.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor], + [_codeInputView.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:500], [_codeInputView.heightAnchor constraintEqualToConstant:50], [_codeInputView.widthAnchor constraintEqualToConstant:300] ]]; + }