Skip to content

Commit

Permalink
新增背景色属性和圆角属性
Browse files Browse the repository at this point in the history
  • Loading branch information
PZXforXcode committed Nov 25, 2024
1 parent b4a7ca6 commit b3ea73a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

@property(nonatomic,assign)CGFloat borderWidth;//格子的border值

@property(nonatomic,assign)CGFloat cornerRadius;//圆角


@property(nonatomic,assign)BOOL lineStyle;//横线样式

Expand All @@ -27,6 +29,9 @@

@property (nonatomic, strong)UIColor *selectedColor;//选中颜色

@property (nonatomic, strong)UIColor *textFieldBackgroundColor;//格子背景颜色


@property (nonatomic, strong)NSMutableArray *textFieldArray;//放textField的array用于在外面好取消键盘

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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]; //绘制界面


Expand Down Expand Up @@ -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];
Expand Down
20 changes: 18 additions & 2 deletions PZXVerificationCodeTextField/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ @interface ViewController () <PZXCodeInputViewDelegate>

@property(nonatomic,strong)PZXVerificationCodeView *SpacingView;

@property(nonatomic,strong)PZXVerificationCodeView *grayView;


@property(nonatomic,strong)UITextField *TF;
- (IBAction)changeButtonPressed:(UIButton *)sender;
- (IBAction)outButtonPressed:(UIButton *)sender;
Expand Down Expand Up @@ -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];

Expand All @@ -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]
]];


}

Expand Down

0 comments on commit b3ea73a

Please sign in to comment.