2019-01-10 12:02:04 +08:00
< a id = "Header_Start" ></ a > 
2019-01-10 11:44:13 +08:00
[](https://travis-ci.org/CRAnimation/CRBoxInputView)
[](https://cocoapods.org/pods/CRBoxInputView)
[](https://cocoapods.org/pods/CRBoxInputView)
[](https://cocoapods.org/pods/CRBoxInputView)
2019-01-16 14:08:56 +08:00
### [中文文档](https://github.com/CRAnimation/CRBoxInputView#Header_Start) [/ English Document](https://github.com/CRAnimation/CRBoxInputView/blob/master/README_en.md#Header_Start)
2019-01-10 11:44:13 +08:00
2020-06-11 21:54:17 +08:00
## Tip
- If you fell good. Could you please give me a star? Thank you.
2019-01-17 11:00:13 +08:00
## Feature
- Support verify code auto fill in iOS12
2019-01-22 12:59:19 +08:00
- Support `Masonry`
2019-01-17 20:34:34 +08:00
- Support security type
- Support custom security image / view
2020-06-11 21:54:17 +08:00
- Support change code length dynamically
2019-01-17 11:00:13 +08:00
> You can use this widget for verify code, password input or phone number input.<br/>I hope you can like this!
2019-01-10 11:44:13 +08:00
## Installation
CRBoxInputView is available through [CocoaPods ](https://cocoapods.org ). To install
it, simply add the following line to your Podfile:
```ruby
2020-06-11 21:54:59 +08:00
pod 'CRBoxInputView', '1.2.1'
2019-01-10 11:44:13 +08:00
```
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
2020-06-11 16:00:30 +08:00

2019-01-10 11:44:13 +08:00
## Quick Guide
| Type | Image |
| :-------------: | :-------------: |
| [Base ](#Anchor_Base ) |  |
2019-07-16 15:51:18 +08:00
| [Placeholder ](#Anchor_Placeholder ) |  |
2019-01-10 11:44:13 +08:00
| [CustomBox ](#Anchor_CustomBox ) |  |
2020-06-11 15:50:00 +08:00
| [Line ](#Anchor_Line ) |  |
2019-01-10 11:44:13 +08:00
| [SecretSymbol ](#Anchor_SecretSymbol ) |  |
| [SecretImage ](#Anchor_SecretImage ) |  |
| [SecretView ](#Anchor_SecretView ) |  |
2020-06-11 21:54:17 +08:00
| [ResetCodeLength ](#Anchor_ResetCodeLength ) |  |
2019-01-10 11:44:13 +08:00
## Usage
### <a id="Anchor_Base"></a>Base

``` objc
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
2019-02-25 15:38:18 +08:00
boxInputView.codeLength = 4;
2019-06-11 12:37:45 +08:00
boxInputView.keyBoardType = UIKeyboardTypeNumberPad;
2019-01-18 12:26:37 +08:00
[boxInputView loadAndPrepareViewWithBeginEdit:YES]; // BeginEdit: If need begin edit.
2019-01-10 11:44:13 +08:00
[self.view addSubview:boxInputView];
2019-01-16 14:06:17 +08:00
2020-06-11 16:33:26 +08:00
// inputType( number)
_boxInputView.inputType = CRInputType_Number;
// inputType( regex)
//_boxInputView.inputType = CRInputType_Regex;
//_boxInputView.customInputRegex = @"[^0-9]";
2019-01-16 14:06:17 +08:00
// Get value
// func1, call back block when input text did change
boxInputView.textDidChangeblock = ^(NSString *text, BOOL isFinished) {
2019-01-16 14:10:07 +08:00
NSLog(@"text:%@", text);
2019-01-16 14:06:17 +08:00
};
// func2, normal readonly property
NSLog(@"textValue:%@", boxInputView.textValue);
2019-01-18 12:26:37 +08:00
// Clear all
[boxInputView clearAllWithBeginEdit:YES]; // BeginEdit: If need begin edit after clear all.
2019-06-11 12:37:45 +08:00
2019-01-10 11:44:13 +08:00
```
2019-07-16 15:51:18 +08:00
< br / >
### <a id="Anchor_Placeholder"></a>Placeholder

``` objc
2019-07-17 06:29:56 +08:00
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.cellPlaceholderTextColor = [UIColor colorWithRed:114/255.0 green:116/255.0 blue:124/255.0 alpha:0.3]; //optional
cellProperty.cellPlaceholderFont = [UIFont systemFontOfSize:20]; //optional
2020-06-11 10:04:56 +08:00
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithCodeLength:4];
2019-07-16 16:37:50 +08:00
boxInputView.ifNeedCursor = NO; //optional
boxInputView.placeholderText = @"露可娜娜"; //required
2019-07-17 06:29:56 +08:00
boxInputView.customCellProperty = cellProperty;
2019-07-16 16:37:50 +08:00
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
2019-07-16 15:51:18 +08:00
```
2019-01-10 11:44:13 +08:00
< br / >
### <a id="Anchor_CustomBox"></a>CustomBox

``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.cellBgColorNormal = color_FFECEC;
cellProperty.cellBgColorSelected = [UIColor whiteColor];
cellProperty.cellCursorColor = color_master;
cellProperty.cellCursorWidth = 2;
2019-06-11 12:37:45 +08:00
cellProperty.cellCursorHeight = 30;
2019-01-10 11:44:13 +08:00
cellProperty.cornerRadius = 4;
cellProperty.borderWidth = 0;
cellProperty.cellFont = [UIFont boldSystemFontOfSize:24];
cellProperty.cellTextColor = color_master;
2019-06-11 12:37:45 +08:00
cellProperty.configCellShadowBlock = ^(CALayer * _Nonnull layer) {
layer.shadowColor = [color_master colorWithAlphaComponent:0.2].CGColor;
layer.shadowOpacity = 1;
layer.shadowOffset = CGSizeMake(0, 2);
layer.shadowRadius = 4;
};
2019-01-10 11:44:13 +08:00
2020-06-11 10:04:56 +08:00
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithCodeLength:4];
2019-01-10 11:44:13 +08:00
boxInputView.boxFlowLayout.itemSize = CGSizeMake(50, 50);
boxInputView.customCellProperty = cellProperty;
2019-06-11 12:37:45 +08:00
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
2019-01-10 11:44:13 +08:00
```
< br / >
### <a id="Anchor_Line"></a>Line
2020-06-11 15:50:00 +08:00

2019-01-10 11:44:13 +08:00
``` objc
2019-06-11 12:37:45 +08:00
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.showLine = YES; //Required
cellProperty.customLineViewBlock = ^CRLineView * _Nonnull{
CRLineView *lineView = [CRLineView new];
2020-01-19 17:17:05 +08:00
lineView.underlineColorNormal = [color_master colorWithAlphaComponent:0.3];
lineView.underlineColorSelected = [color_master colorWithAlphaComponent:0.7];
lineView.underlineColorFilled = color_master;
2019-06-11 12:37:45 +08:00
[lineView.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(4);
make.left.right.bottom.offset(0);
}];
2020-06-11 16:16:04 +08:00
lineView.selectChangeBlock = ^(CRLineView * _Nonnull lineView, BOOL selected) {
if (selected) {
[lineView.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(6);
}];
} else {
[lineView.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(4);
}];
}
};
2019-06-11 12:37:45 +08:00
return lineView;
}; //Optional
2020-06-11 10:04:56 +08:00
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithCodeLength:4];
2019-06-11 12:37:45 +08:00
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
2019-01-10 11:44:13 +08:00
```
< br / >
### <a id="Anchor_SecretSymbol"></a>SecretSymbol

``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
2019-06-11 12:37:45 +08:00
cellProperty.securitySymbol = @"*"; //Optional
2019-01-10 11:44:13 +08:00
2020-06-11 10:04:56 +08:00
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithCodeLength:4];
2019-07-19 00:32:29 +08:00
boxInputView.ifNeedSecurity = YES; //Required (You can change this property anytime. And the existing texts can be refreshed automatically.)
2019-01-10 11:44:13 +08:00
boxInputView.customCellProperty = cellProperty;
2020-01-20 16:48:05 +08:00
[boxInputView loadAndPrepareViewWithBeginEdit:NO];
_boxInputView.ifClearAllInBeginEditing = YES;
[_boxInputView reloadInputString:@"5678"];
2019-01-10 11:44:13 +08:00
```
< br / >
### <a id="Anchor_SecretImage"></a>SecretImage

``` objc
2019-06-11 12:37:45 +08:00
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.securityType = CRBoxSecurityCustomViewType; //Required
cellProperty.customSecurityViewBlock = ^UIView * _Nonnull{
CRSecrectImageView *secrectImageView = [CRSecrectImageView new];
secrectImageView.image = [UIImage imageNamed:@"smallLock"];
secrectImageView.imageWidth = 23;
secrectImageView.imageHeight = 27;
return secrectImageView;
}; //Required
2020-06-11 10:04:56 +08:00
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithCodeLength:4];
2019-07-19 00:32:29 +08:00
boxInputView.ifNeedSecurity = YES; //Required (You can change this property anytime. And the existing texts can be refreshed automatically.)
2019-06-11 12:37:45 +08:00
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
2019-01-10 11:44:13 +08:00
```
< br / >
### <a id="Anchor_SecretView"></a>SecretView

``` objc
2019-06-11 12:37:45 +08:00
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.securityType = CRBoxSecurityCustomViewType; //Required
cellProperty.customSecurityViewBlock = ^UIView * _Nonnull{
UIView *customSecurityView = [UIView new];
customSecurityView.backgroundColor = [UIColor clearColor];
// circleView
static CGFloat circleViewWidth = 20;
UIView *circleView = [UIView new];
circleView.backgroundColor = color_master;
circleView.layer.cornerRadius = 4;
[customSecurityView addSubview:circleView];
[circleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(circleViewWidth);
make.centerX.offset(0);
make.centerY.offset(0);
}];
return customSecurityView;
}; //Optional
2020-06-11 10:04:56 +08:00
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithCodeLength:4];
2019-07-19 00:32:29 +08:00
boxInputView.ifNeedSecurity = YES; //Required (You can change this property anytime. And the existing texts can be refreshed automatically.)
2019-06-11 12:37:45 +08:00
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
2019-01-10 11:44:13 +08:00
```
2020-06-11 21:54:17 +08:00
< br / >
### <a id="Anchor_ResetCodeLength"></a>ResetCodeLength
2020-06-11 22:03:44 +08:00

2020-06-11 21:54:17 +08:00
``` objc
[boxInputView resetCodeLength:_boxInputView.codeLength+1 beginEdit:YES];
```
2019-01-10 11:44:13 +08:00
< br / >
2019-06-11 12:37:45 +08:00
## Properties And Functions
2019-11-13 12:03:35 +08:00
`CRBoxInputCellProperty`
2019-01-10 11:44:13 +08:00
``` objc
2019-06-11 12:37:45 +08:00
#pragma mark - UI
@property (assign, nonatomic) CGFloat borderWidth;
@property (copy, nonatomic) UIColor *cellBorderColorNormal;
@property (copy, nonatomic) UIColor *cellBorderColorSelected;
@property (copy, nonatomic) UIColor *__nullable cellBorderColorFilled;
@property (copy, nonatomic) UIColor *cellBgColorNormal;
@property (copy, nonatomic) UIColor *cellBgColorSelected;
@property (copy, nonatomic) UIColor *__nullable cellBgColorFilled;
2019-11-13 12:00:09 +08:00
@property (assign, nonatomic) CGFloat cornerRadius;
2019-01-10 11:44:13 +08:00
2019-11-13 12:00:09 +08:00
#pragma mark - cursor
2019-06-11 12:37:45 +08:00
@property (copy, nonatomic) UIColor *cellCursorColor;
@property (assign, nonatomic) CGFloat cellCursorWidth;
@property (assign, nonatomic) CGFloat cellCursorHeight;
2019-01-10 11:44:13 +08:00
2019-11-13 12:00:09 +08:00
#pragma mark - line
@property (assign, nonatomic) BOOL showLine;
#pragma mark - label
@property (copy, nonatomic) UIFont *cellFont;
@property (copy, nonatomic) UIColor *cellTextColor;
#pragma mark - Security
@property (assign, nonatomic) BOOL ifShowSecurity;
@property (copy, nonatomic) NSString *securitySymbol;
@property (assign, nonatomic) CRBoxSecurityType securityType;
#pragma mark - Placeholder
@property (copy, nonatomic) UIColor *cellPlaceholderTextColor;
@property (copy, nonatomic) UIFont *cellPlaceholderFont;
#pragma mark - Block
@property (copy, nonatomic) CustomSecurityViewBlock customSecurityViewBlock;
@property (copy, nonatomic) CustomLineViewBlock customLineViewBlock;
@property (copy, nonatomic) ConfigCellShadowBlock __nullable configCellShadowBlock;
2019-01-10 11:44:13 +08:00
```
2019-11-13 12:03:35 +08:00
`CRBoxFlowLayout`
2019-01-10 11:44:13 +08:00
``` objc
@property (assign, nonatomic) BOOL ifNeedEqualGap;
@property (assign, nonatomic) NSInteger itemNum;
```
2019-11-13 12:03:35 +08:00
`CRBoxInputView`
2019-01-10 11:44:13 +08:00
``` objc
2019-11-13 12:00:09 +08:00
// Security
2019-01-10 11:44:13 +08:00
@property (assign, nonatomic) BOOL ifNeedSecurity;
@property (assign, nonatomic) CGFloat securityDelay;
2019-11-13 12:00:09 +08:00
@property (assign, nonatomic) BOOL ifNeedCursor;
@property (nonatomic, assign) NSInteger codeLength;
2019-01-10 11:44:13 +08:00
@property (assign, nonatomic) UIKeyboardType keyBoardType;
2019-01-10 23:51:17 +08:00
@property (null_unspecified,nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0);
2019-07-16 15:07:08 +08:00
@property (strong, nonatomic) NSString * _Nullable placeholderText;
2020-01-20 16:48:05 +08:00
@property (assign, nonatomic) BOOL ifClearAllInBeginEditing;
2019-07-16 15:07:08 +08:00
2019-11-13 12:00:09 +08:00
@property (copy, nonatomic) TextDidChangeblock _Nullable textDidChangeblock;
2020-01-20 16:48:05 +08:00
@property (copy, nonatomic) TextEditStatusChangeblock _Nullable textEditStatusChangeblock;
2019-11-13 12:00:09 +08:00
@property (strong, nonatomic) CRBoxFlowLayout * _Nullable boxFlowLayout;
@property (strong, nonatomic) CRBoxInputCellProperty * _Nullable customCellProperty;
@property (strong, nonatomic, readonly) NSString * _Nullable textValue;
2019-07-01 11:22:29 +08:00
@property (strong, nonatomic) UIView * _Nullable inputAccessoryView;
2019-01-10 11:44:13 +08:00
2019-01-18 12:26:37 +08:00
- (void)loadAndPrepareView;
- (void)loadAndPrepareViewWithBeginEdit:(BOOL)beginEdit;
2020-01-20 16:48:05 +08:00
- (void)reloadInputString:(NSString *_Nullable)value; // Reload string. (You can use this function to set deault value)
2019-01-18 12:26:37 +08:00
- (void)clearAll;
- (void)clearAllWithBeginEdit:(BOOL)beginEdit;
2019-11-13 12:00:09 +08:00
- (UICollectionView *_Nullable)mainCollectionView;
- (void)quickSetSecuritySymbol:(NSString *_Nullable)securitySymbol;
2019-01-10 11:44:13 +08:00
// You can inherit and call super
- (void)initDefaultValue;
2019-11-13 12:00:09 +08:00
- (UICollectionViewCell *_Nullable)customCollectionView:(UICollectionView *_Nullable)collectionView cellForItemAtIndexPath:(NSIndexPath *_Nullable)indexPath;
2019-01-10 11:44:13 +08:00
```
2019-11-13 12:03:35 +08:00
`CRBoxInputCell`
2019-01-10 11:44:13 +08:00
``` objc
// You can inherit and rewrite
- (UIView *)createCustomSecurityView;
```
2019-11-13 12:03:35 +08:00
`CRLineView`
2019-08-01 17:56:43 +08:00
``` objc
@property (strong, nonatomic) UIView *lineView;
@property (copy, nonatomic) UIColor *underlineColorNormal;
@property (copy, nonatomic) UIColor *underlineColorSelected;
2020-01-19 17:17:05 +08:00
@property (copy, nonatomic) UIColor *underlineColorFilled;
2019-08-01 17:56:43 +08:00
```
2019-01-11 17:54:32 +08:00
## Other Problems
- [pod search unable find a pod( already solved) ](https://github.com/CRAnimation/CRBoxInputView/issues/1 "pod search unable find a pod" )
2019-01-17 11:04:32 +08:00
- [pod installation failed, [!] Unable to find a specification for CRBoxInputView( already solved) ](https://github.com/CRAnimation/CRBoxInputView/issues/2 "pod installation failed, [!] Unable to find a specification for CRBoxInputView")
2019-01-11 17:54:32 +08:00
2019-01-10 11:44:13 +08:00
## Author
BearRan, 648070256@qq .com
## Feedback
If you have any other problems about this widget, you can tell me by send E-mail or open a issuse.
## License
CRBoxInputView is available under the MIT license. See the LICENSE file for more info.