Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
 Committer: HaoCold <mac1@mac1s-iMac.local>
  • Loading branch information
mac1 authored and mac1 committed Oct 16, 2018
1 parent 8ee7f28 commit b322862
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 33 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file removed 123.png
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>JHVerificationCodeView.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ typedef NS_ENUM(NSUInteger, JHVCConfigInputType) {
@property (assign, nonatomic) CGFloat inputBoxWidth;
///单个输入框的高度
@property (assign, nonatomic) CGFloat inputBoxHeight;
///单个输入框的边框宽度
///单个输入框的边框宽度, Default is 1 pixel
@property (assign, nonatomic) CGFloat inputBoxBorderWidth;
///输入框间距
///单个输入框的边框圆角
@property (assign, nonatomic) CGFloat inputBoxCornerRadius;
///输入框间距, Default is 5
@property (assign, nonatomic) CGFloat inputBoxSpacing;
///左边距
@property (assign, nonatomic) CGFloat leftMargin;
///单个输入框的颜色
///单个输入框的颜色, Default is lightGrayColor
@property (strong, nonatomic) UIColor *inputBoxColor;
///单个输入框输入时的颜色
@property (strong, nonatomic) UIColor *inputBoxHighlightedColor;
///光标颜色
@property (strong, nonatomic) UIColor *tintColor;
///显示 或 隐藏
Expand All @@ -60,6 +64,10 @@ typedef NS_ENUM(NSUInteger, JHVCConfigInputType) {
@property (strong, nonatomic) UIColor *textColor;
///输入类型:数字+字母,数字,字母. Default is 'JHVCConfigInputType_Number_Alphabet'
@property (nonatomic, assign) JHVCConfigInputType inputType;
///自动弹出键盘
@property (nonatomic, assign) BOOL autoShowKeyboard;
///
@property (nonatomic, assign) BOOL useTextColor;
@end

@interface JHVerificationCodeView : UIView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ @implementation JHVCConfig

- (instancetype)init{
if (self = [super init]) {
_inputBoxBorderWidth = 1.0/[UIScreen mainScreen].scale;
_inputBoxSpacing = 5;
_inputBoxColor = [UIColor lightGrayColor];
}
return self;
}
Expand Down Expand Up @@ -99,11 +101,12 @@ - (void)jhSetupViews:(CGRect)frame
UITextField *textField = [[UITextField alloc] init];
textField.frame = CGRectMake(_config.leftMargin+(inputBoxWidth+inputBoxSpacing)*i, (CGRectGetHeight(frame)-inputBoxHeight)*0.5, inputBoxWidth, inputBoxHeight);
textField.textAlignment = 1;
textField.layer.borderWidth = 0.5;
textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
if (_config.inputBoxBorderWidth) {
textField.layer.borderWidth = _config.inputBoxBorderWidth;
}
if (_config.inputBoxCornerRadius) {
textField.layer.cornerRadius = _config.inputBoxCornerRadius;
}
if (_config.inputBoxColor) {
textField.layer.borderColor = _config.inputBoxColor.CGColor;
}
Expand Down Expand Up @@ -135,9 +138,11 @@ - (void)jhSetupViews:(CGRect)frame
[self addSubview:_textView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange:) name:UITextViewTextDidChangeNotification object:_textView];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_textView becomeFirstResponder];
});
if (_config.autoShowKeyboard) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_textView becomeFirstResponder];
});
}
}

- (void)xx_tap{
Expand Down Expand Up @@ -189,12 +194,20 @@ - (void)textChange:(NSNotification *)noti
for (int i = 0; i < 6; ++i) {
UITextField *textField = self.subviews[i];
textField.text = @"";

if (_config.inputBoxColor) {
textField.layer.borderColor = _config.inputBoxColor.CGColor;
}
}

for (int i = 0; i < text.length; ++i) {
unichar c = [text characterAtIndex:i];
UITextField *textField = self.subviews[i];
textField.text = [NSString stringWithFormat:@"%c",c];

if (_config.inputBoxHighlightedColor) {
textField.layer.borderColor = _config.inputBoxHighlightedColor.CGColor;
}
}

if (text.length == 6) {
Expand Down
143 changes: 118 additions & 25 deletions JHVerificationCodeView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,125 @@ - (void)viewDidLoad {

- (void)jhSetupViews
{
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 150, kScreenWidth, 30);
label.textAlignment = 1;
[self.view addSubview:label];

JHVCConfig *config = [[JHVCConfig alloc] init];
config.inputBoxNumber = 6;
config.inputBoxSpacing = 5;
config.inputBoxWidth = 33;
config.inputBoxHeight = 28;
config.tintColor = [UIColor blackColor];
config.secureTextEntry = NO;
config.inputBoxColor = [UIColor brownColor];
config.font = [UIFont boldSystemFontOfSize:16];
config.textColor = [UIColor brownColor];
config.inputType = JHVCConfigInputType_Number_Alphabet;
// example 1
{
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 120, kScreenWidth, 30);
label.textAlignment = 1;
label.text = @"InputType: Number & Alphabet";
[self.view addSubview:label];

JHVCConfig *config = [[JHVCConfig alloc] init];
config.inputBoxNumber = 6;
config.inputBoxSpacing = 5;
config.inputBoxWidth = 33;
config.inputBoxHeight = 28;
config.tintColor = [UIColor blackColor];
config.secureTextEntry = NO;
config.inputBoxColor = [UIColor brownColor];
config.font = [UIFont boldSystemFontOfSize:16];
config.textColor = [UIColor blueColor];
config.inputType = JHVCConfigInputType_Number_Alphabet;

config.inputBoxBorderWidth = 1;
config.inputBoxCornerRadius = 5;


[self.view addSubview:({

UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 180, kScreenWidth, 30);
label.textAlignment = 1;
[self.view addSubview:label];

JHVerificationCodeView *codeView =
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 150, kScreenWidth-20, 30)
config:config];
codeView.finishBlock = ^(NSString *code) {
label.text = code;
};
codeView;
})];
}

// example 2
{
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 210, kScreenWidth, 30);
label.textAlignment = 1;
label.text = @"InputType: Number";
[self.view addSubview:label];

JHVCConfig *config = [[JHVCConfig alloc] init];
config.inputBoxNumber = 6;
config.inputBoxSpacing = 5;
config.inputBoxWidth = 33;
config.inputBoxHeight = 28;
config.tintColor = [UIColor blackColor];
config.secureTextEntry = NO;
config.inputBoxColor = [UIColor brownColor];
config.font = [UIFont boldSystemFontOfSize:16];
config.textColor = [UIColor cyanColor];
config.inputType = JHVCConfigInputType_Number;

config.inputBoxBorderWidth = 1;
config.inputBoxHighlightedColor = [UIColor purpleColor];

[self.view addSubview:({

UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 270, kScreenWidth, 30);
label.textAlignment = 1;
[self.view addSubview:label];

JHVerificationCodeView *codeView =
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 240, kScreenWidth-20, 30)
config:config];
codeView.finishBlock = ^(NSString *code) {
label.text = code;
};
codeView;
})];
}

[self.view addSubview:({
JHVerificationCodeView *codeView =
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 100, kScreenWidth-20, 30)
config:config];
codeView.finishBlock = ^(NSString *code) {
label.text = code;
};
codeView;
})];
// example 3
{
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 300, kScreenWidth, 30);
label.textAlignment = 1;
label.text = @"InputType: Alphabet";
[self.view addSubview:label];

JHVCConfig *config = [[JHVCConfig alloc] init];
config.inputBoxNumber = 6;
config.inputBoxSpacing = -1;
config.inputBoxWidth = 33;
config.inputBoxHeight = 28;
config.tintColor = [UIColor blackColor];
config.secureTextEntry = NO;
config.inputBoxColor = [UIColor brownColor];
config.font = [UIFont boldSystemFontOfSize:16];
config.textColor = [UIColor grayColor];
config.inputType = JHVCConfigInputType_Alphabet;

config.inputBoxBorderWidth = 1;

[self.view addSubview:({

UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 360, kScreenWidth, 30);
label.textAlignment = 1;
[self.view addSubview:label];

JHVerificationCodeView *codeView =
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 330, kScreenWidth-20, 30)
config:config];
codeView.finishBlock = ^(NSString *code) {
label.text = code;
};
codeView;
})];
}

}

Expand Down
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b322862

Please sign in to comment.