Skip to content

Commit b322862

Browse files
mac1mac1
authored andcommitted
1.2.0
Committer: HaoCold <[email protected]>
1 parent 8ee7f28 commit b322862

File tree

8 files changed

+161
-33
lines changed

8 files changed

+161
-33
lines changed

.DS_Store

6 KB
Binary file not shown.

123.png

-79.7 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>JHVerificationCodeView.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
</dict>
14+
</plist>

JHVerificationCodeView/JHVerificationCodeView/JHVerificationCodeView.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ typedef NS_ENUM(NSUInteger, JHVCConfigInputType) {
4242
@property (assign, nonatomic) CGFloat inputBoxWidth;
4343
///单个输入框的高度
4444
@property (assign, nonatomic) CGFloat inputBoxHeight;
45-
///单个输入框的边框宽度
45+
///单个输入框的边框宽度, Default is 1 pixel
4646
@property (assign, nonatomic) CGFloat inputBoxBorderWidth;
47-
///输入框间距
47+
///单个输入框的边框圆角
48+
@property (assign, nonatomic) CGFloat inputBoxCornerRadius;
49+
///输入框间距, Default is 5
4850
@property (assign, nonatomic) CGFloat inputBoxSpacing;
4951
///左边距
5052
@property (assign, nonatomic) CGFloat leftMargin;
51-
///单个输入框的颜色
53+
///单个输入框的颜色, Default is lightGrayColor
5254
@property (strong, nonatomic) UIColor *inputBoxColor;
55+
///单个输入框输入时的颜色
56+
@property (strong, nonatomic) UIColor *inputBoxHighlightedColor;
5357
///光标颜色
5458
@property (strong, nonatomic) UIColor *tintColor;
5559
///显示 或 隐藏
@@ -60,6 +64,10 @@ typedef NS_ENUM(NSUInteger, JHVCConfigInputType) {
6064
@property (strong, nonatomic) UIColor *textColor;
6165
///输入类型:数字+字母,数字,字母. Default is 'JHVCConfigInputType_Number_Alphabet'
6266
@property (nonatomic, assign) JHVCConfigInputType inputType;
67+
///自动弹出键盘
68+
@property (nonatomic, assign) BOOL autoShowKeyboard;
69+
///
70+
@property (nonatomic, assign) BOOL useTextColor;
6371
@end
6472

6573
@interface JHVerificationCodeView : UIView

JHVerificationCodeView/JHVerificationCodeView/JHVerificationCodeView.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ @implementation JHVCConfig
3333

3434
- (instancetype)init{
3535
if (self = [super init]) {
36+
_inputBoxBorderWidth = 1.0/[UIScreen mainScreen].scale;
3637
_inputBoxSpacing = 5;
38+
_inputBoxColor = [UIColor lightGrayColor];
3739
}
3840
return self;
3941
}
@@ -99,11 +101,12 @@ - (void)jhSetupViews:(CGRect)frame
99101
UITextField *textField = [[UITextField alloc] init];
100102
textField.frame = CGRectMake(_config.leftMargin+(inputBoxWidth+inputBoxSpacing)*i, (CGRectGetHeight(frame)-inputBoxHeight)*0.5, inputBoxWidth, inputBoxHeight);
101103
textField.textAlignment = 1;
102-
textField.layer.borderWidth = 0.5;
103-
textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
104104
if (_config.inputBoxBorderWidth) {
105105
textField.layer.borderWidth = _config.inputBoxBorderWidth;
106106
}
107+
if (_config.inputBoxCornerRadius) {
108+
textField.layer.cornerRadius = _config.inputBoxCornerRadius;
109+
}
107110
if (_config.inputBoxColor) {
108111
textField.layer.borderColor = _config.inputBoxColor.CGColor;
109112
}
@@ -135,9 +138,11 @@ - (void)jhSetupViews:(CGRect)frame
135138
[self addSubview:_textView];
136139
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange:) name:UITextViewTextDidChangeNotification object:_textView];
137140

138-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
139-
[_textView becomeFirstResponder];
140-
});
141+
if (_config.autoShowKeyboard) {
142+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
143+
[_textView becomeFirstResponder];
144+
});
145+
}
141146
}
142147

143148
- (void)xx_tap{
@@ -189,12 +194,20 @@ - (void)textChange:(NSNotification *)noti
189194
for (int i = 0; i < 6; ++i) {
190195
UITextField *textField = self.subviews[i];
191196
textField.text = @"";
197+
198+
if (_config.inputBoxColor) {
199+
textField.layer.borderColor = _config.inputBoxColor.CGColor;
200+
}
192201
}
193202

194203
for (int i = 0; i < text.length; ++i) {
195204
unichar c = [text characterAtIndex:i];
196205
UITextField *textField = self.subviews[i];
197206
textField.text = [NSString stringWithFormat:@"%c",c];
207+
208+
if (_config.inputBoxHighlightedColor) {
209+
textField.layer.borderColor = _config.inputBoxHighlightedColor.CGColor;
210+
}
198211
}
199212

200213
if (text.length == 6) {

JHVerificationCodeView/ViewController.m

Lines changed: 118 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,125 @@ - (void)viewDidLoad {
3030

3131
- (void)jhSetupViews
3232
{
33-
UILabel *label = [[UILabel alloc] init];
34-
label.frame = CGRectMake(0, 150, kScreenWidth, 30);
35-
label.textAlignment = 1;
36-
[self.view addSubview:label];
37-
38-
JHVCConfig *config = [[JHVCConfig alloc] init];
39-
config.inputBoxNumber = 6;
40-
config.inputBoxSpacing = 5;
41-
config.inputBoxWidth = 33;
42-
config.inputBoxHeight = 28;
43-
config.tintColor = [UIColor blackColor];
44-
config.secureTextEntry = NO;
45-
config.inputBoxColor = [UIColor brownColor];
46-
config.font = [UIFont boldSystemFontOfSize:16];
47-
config.textColor = [UIColor brownColor];
48-
config.inputType = JHVCConfigInputType_Number_Alphabet;
33+
// example 1
34+
{
35+
UILabel *label = [[UILabel alloc] init];
36+
label.frame = CGRectMake(0, 120, kScreenWidth, 30);
37+
label.textAlignment = 1;
38+
label.text = @"InputType: Number & Alphabet";
39+
[self.view addSubview:label];
40+
41+
JHVCConfig *config = [[JHVCConfig alloc] init];
42+
config.inputBoxNumber = 6;
43+
config.inputBoxSpacing = 5;
44+
config.inputBoxWidth = 33;
45+
config.inputBoxHeight = 28;
46+
config.tintColor = [UIColor blackColor];
47+
config.secureTextEntry = NO;
48+
config.inputBoxColor = [UIColor brownColor];
49+
config.font = [UIFont boldSystemFontOfSize:16];
50+
config.textColor = [UIColor blueColor];
51+
config.inputType = JHVCConfigInputType_Number_Alphabet;
52+
53+
config.inputBoxBorderWidth = 1;
54+
config.inputBoxCornerRadius = 5;
55+
56+
57+
[self.view addSubview:({
58+
59+
UILabel *label = [[UILabel alloc] init];
60+
label.frame = CGRectMake(0, 180, kScreenWidth, 30);
61+
label.textAlignment = 1;
62+
[self.view addSubview:label];
63+
64+
JHVerificationCodeView *codeView =
65+
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 150, kScreenWidth-20, 30)
66+
config:config];
67+
codeView.finishBlock = ^(NSString *code) {
68+
label.text = code;
69+
};
70+
codeView;
71+
})];
72+
}
73+
74+
// example 2
75+
{
76+
UILabel *label = [[UILabel alloc] init];
77+
label.frame = CGRectMake(0, 210, kScreenWidth, 30);
78+
label.textAlignment = 1;
79+
label.text = @"InputType: Number";
80+
[self.view addSubview:label];
81+
82+
JHVCConfig *config = [[JHVCConfig alloc] init];
83+
config.inputBoxNumber = 6;
84+
config.inputBoxSpacing = 5;
85+
config.inputBoxWidth = 33;
86+
config.inputBoxHeight = 28;
87+
config.tintColor = [UIColor blackColor];
88+
config.secureTextEntry = NO;
89+
config.inputBoxColor = [UIColor brownColor];
90+
config.font = [UIFont boldSystemFontOfSize:16];
91+
config.textColor = [UIColor cyanColor];
92+
config.inputType = JHVCConfigInputType_Number;
93+
94+
config.inputBoxBorderWidth = 1;
95+
config.inputBoxHighlightedColor = [UIColor purpleColor];
96+
97+
[self.view addSubview:({
98+
99+
UILabel *label = [[UILabel alloc] init];
100+
label.frame = CGRectMake(0, 270, kScreenWidth, 30);
101+
label.textAlignment = 1;
102+
[self.view addSubview:label];
103+
104+
JHVerificationCodeView *codeView =
105+
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 240, kScreenWidth-20, 30)
106+
config:config];
107+
codeView.finishBlock = ^(NSString *code) {
108+
label.text = code;
109+
};
110+
codeView;
111+
})];
112+
}
49113

50-
[self.view addSubview:({
51-
JHVerificationCodeView *codeView =
52-
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 100, kScreenWidth-20, 30)
53-
config:config];
54-
codeView.finishBlock = ^(NSString *code) {
55-
label.text = code;
56-
};
57-
codeView;
58-
})];
114+
// example 3
115+
{
116+
UILabel *label = [[UILabel alloc] init];
117+
label.frame = CGRectMake(0, 300, kScreenWidth, 30);
118+
label.textAlignment = 1;
119+
label.text = @"InputType: Alphabet";
120+
[self.view addSubview:label];
121+
122+
JHVCConfig *config = [[JHVCConfig alloc] init];
123+
config.inputBoxNumber = 6;
124+
config.inputBoxSpacing = -1;
125+
config.inputBoxWidth = 33;
126+
config.inputBoxHeight = 28;
127+
config.tintColor = [UIColor blackColor];
128+
config.secureTextEntry = NO;
129+
config.inputBoxColor = [UIColor brownColor];
130+
config.font = [UIFont boldSystemFontOfSize:16];
131+
config.textColor = [UIColor grayColor];
132+
config.inputType = JHVCConfigInputType_Alphabet;
133+
134+
config.inputBoxBorderWidth = 1;
135+
136+
[self.view addSubview:({
137+
138+
UILabel *label = [[UILabel alloc] init];
139+
label.frame = CGRectMake(0, 360, kScreenWidth, 30);
140+
label.textAlignment = 1;
141+
[self.view addSubview:label];
142+
143+
JHVerificationCodeView *codeView =
144+
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 330, kScreenWidth-20, 30)
145+
config:config];
146+
codeView.finishBlock = ^(NSString *code) {
147+
label.text = code;
148+
};
149+
codeView;
150+
})];
151+
}
59152

60153
}
61154

image.png

63.3 KB
Loading

0 commit comments

Comments
 (0)