This commit is contained in:
启星
2025-08-11 10:43:19 +08:00
commit fb2c58d96f
8839 changed files with 709982 additions and 0 deletions

19
Pods/CRBoxInputView/LICENSE generated Executable file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2019 BearRan <648070256@qq.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,26 @@
//
// CRBoxFlowLayout.h
// CaiShenYe
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CRBoxFlowLayout : UICollectionViewFlowLayout
/** ifNeedEqualGap
* default: YES
*/
@property (assign, nonatomic) BOOL ifNeedEqualGap;
@property (assign, nonatomic) NSInteger itemNum;
- (void)autoCalucateLineSpacing;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,53 @@
//
// CRBoxFlowLayout.m
// CaiShenYe
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import "CRBoxFlowLayout.h"
@implementation CRBoxFlowLayout
- (instancetype)init
{
self = [super init];
if (self) {
[self initPara];
}
return self;
}
- (void)initPara
{
self.ifNeedEqualGap = YES;
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.minimumLineSpacing = 0;
self.minimumInteritemSpacing = 0;
self.sectionInset = UIEdgeInsetsZero;
self.itemNum = 1;
}
- (void)prepareLayout
{
if (_ifNeedEqualGap) {
[self autoCalucateLineSpacing];
}
[super prepareLayout];
}
- (void)autoCalucateLineSpacing
{
if (self.itemNum > 1) {
CGFloat width = CGRectGetWidth(self.collectionView.frame);
self.minimumLineSpacing = floor(1.0 * (width - self.itemNum * self.itemSize.width) / (self.itemNum - 1));
}else{
self.minimumLineSpacing = 0;
}
}
@end

View File

@@ -0,0 +1,38 @@
//
// CRBoxInputCell.h
// CaiShenYe
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "CRBoxInputCellProperty.h"
NS_ASSUME_NONNULL_BEGIN
#define CRBoxCursoryAnimationKey @"CRBoxCursoryAnimationKey"
#define CRBoxInputCellID @"CRBoxInputCellID"
@interface CRBoxInputCell : UICollectionViewCell
/**
cursor
You should not use these properties, unless you know what you are doing.
*/
@property (strong, nonatomic) UIView *cursorView;
@property (assign, nonatomic) BOOL ifNeedCursor;
/**
boxInputCellProperty
You should not use these properties, unless you know what you are doing.
*/
@property (strong, nonatomic) CRBoxInputCellProperty *boxInputCellProperty;
// 你可以在继承的子类中重写父类方法
// You can inherit and rewrite
- (UIView *)createCustomSecurityView __deprecated_msg("Please use `customSecurityViewBlock` in CRBoxInputCellProperty.");
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,226 @@
//
// CRBoxInputCell.m
// CaiShenYe
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import "CRBoxInputCell.h"
#import <Masonry/Masonry.h>
@interface CRBoxInputCell ()
{
}
@property (strong, nonatomic) UILabel *valueLabel;
@property (strong, nonatomic) CABasicAnimation *opacityAnimation;
@property (strong, nonatomic) UIView *customSecurityView;
@property (strong, nonatomic) UIView *lineView;
@end
@implementation CRBoxInputCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createUIBase];
}
return self;
}
- (void)initPara
{
self.ifNeedCursor = YES;
self.userInteractionEnabled = NO;
}
- (void)createUIBase
{
[self initPara];
_valueLabel = [UILabel new];
_valueLabel.font = [UIFont systemFontOfSize:38];
[self.contentView addSubview:_valueLabel];
[_valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.offset(0);
make.centerY.offset(0);
}];
_cursorView = [UIView new];
[self.contentView addSubview:_cursorView];
[_cursorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.offset(0);
make.centerY.offset(0);
}];
[self initCellProperty];
}
- (void)initCellProperty
{
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
self.boxInputCellProperty = cellProperty;
}
- (void)valueLabelLoadData
{
_valueLabel.hidden = NO;
[self hideCustomSecurityView];
BOOL hasOriginValue = self.boxInputCellProperty.originValue && self.boxInputCellProperty.originValue.length > 0;
if (hasOriginValue) {
if (self.boxInputCellProperty.ifShowSecurity) {
if (self.boxInputCellProperty.securityType == CRBoxSecuritySymbolType) {
_valueLabel.text = self.boxInputCellProperty.securitySymbol;
}else if (self.boxInputCellProperty.securityType == CRBoxSecurityCustomViewType) {
_valueLabel.hidden = YES;
[self showCustomSecurityView];
}
}else{
_valueLabel.text = self.boxInputCellProperty.originValue;
}
}else{
_valueLabel.text = @"";
}
}
#pragma mark - Custom security view
- (void)showCustomSecurityView
{
if (!self.customSecurityView.superview) {
[self.contentView addSubview:self.customSecurityView];
[self.customSecurityView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsZero);
}];
}
self.customSecurityView.alpha = 1;
}
- (void)hideCustomSecurityView
{
// Must add this judge. Otherwise _customSecurityView maybe null, and cause error.
if (_customSecurityView) {
self.customSecurityView.alpha = 0;
}
}
#pragma mark - Setter & Getter
- (CABasicAnimation *)opacityAnimation
{
if (!_opacityAnimation) {
_opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
_opacityAnimation.fromValue = @(1.0);
_opacityAnimation.toValue = @(0.0);
_opacityAnimation.duration = 0.9;
_opacityAnimation.repeatCount = HUGE_VALF;
_opacityAnimation.removedOnCompletion = YES;
_opacityAnimation.fillMode = kCAFillModeForwards;
_opacityAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
}
return _opacityAnimation;
}
- (void)setSelected:(BOOL)selected
{
if (selected) {
self.layer.borderColor = self.boxInputCellProperty.cellBorderColorSelected.CGColor;
self.backgroundColor = self.boxInputCellProperty.cellBgColorSelected;
}else{
BOOL hasFill = _valueLabel.text.length > 0 ? YES : NO;
UIColor *cellBorderColor = self.boxInputCellProperty.cellBorderColorNormal;
UIColor *cellBackgroundColor = self.boxInputCellProperty.cellBgColorNormal;
if (hasFill) {
if (self.boxInputCellProperty.cellBorderColorFilled) {
cellBorderColor = self.boxInputCellProperty.cellBorderColorFilled;
}
if (self.boxInputCellProperty.cellBgColorFilled) {
cellBackgroundColor = self.boxInputCellProperty.cellBgColorFilled;
}
}
self.layer.borderColor = cellBorderColor.CGColor;
self.backgroundColor = cellBackgroundColor;
}
if (_ifNeedCursor) {
if (selected) {
_cursorView.hidden= NO;
[_cursorView.layer addAnimation:self.opacityAnimation forKey:CRBoxCursoryAnimationKey];
}else{
_cursorView.hidden= YES;
[_cursorView.layer removeAnimationForKey:CRBoxCursoryAnimationKey];
}
}else{
_cursorView.hidden= YES;
}
}
- (void)setBoxInputCellProperty:(CRBoxInputCellProperty *)boxInputCellProperty
{
_boxInputCellProperty = boxInputCellProperty;
_cursorView.backgroundColor = boxInputCellProperty.cellCursorColor;
[_cursorView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(boxInputCellProperty.cellCursorWidth);
make.height.mas_equalTo(boxInputCellProperty.cellCursorHeight);
}];
self.layer.cornerRadius = boxInputCellProperty.cornerRadius;
self.layer.borderWidth = boxInputCellProperty.borderWidth;
if (boxInputCellProperty.cellFont) {
_valueLabel.font = boxInputCellProperty.cellFont;
}
if (boxInputCellProperty.cellTextColor) {
_valueLabel.textColor = boxInputCellProperty.cellTextColor;
}
[self valueLabelLoadData];
}
- (UIView *)customSecurityView
{
if (!_customSecurityView) {
// Compatiable for 0.19 verion and earlier.
if ([self respondsToSelector:@selector(createCustomSecurityView)]) {
_customSecurityView = [self createCustomSecurityView];
}
else if(_boxInputCellProperty.customSecurityViewBlock){
NSAssert(_boxInputCellProperty.customSecurityViewBlock, @"customSecurityViewBlock can not be null");
_customSecurityView = _boxInputCellProperty.customSecurityViewBlock();
}
}
return _customSecurityView;
}
- (void)layoutSubviews
{
__weak typeof(self) weakSelf = self;
if (_boxInputCellProperty.showLine && !_lineView) {
NSAssert(_boxInputCellProperty.customLineViewBlock, @"customLineViewBlock can not be null");
_lineView = _boxInputCellProperty.customLineViewBlock();
[self.contentView addSubview:_lineView];
[_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.top.offset(0);
}];
}
if (_boxInputCellProperty.configCellShadowBlock) {
_boxInputCellProperty.configCellShadowBlock(weakSelf.layer);
}
[super layoutSubviews];
}
@end

View File

@@ -0,0 +1,178 @@
//
// CRBoxInputCellProperty.h
// CaiShenYe
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CRBoxInputView/CRLineView.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, CRBoxSecurityType) {
CRBoxSecuritySymbolType,
CRBoxSecurityCustomViewType,
};
typedef UIView *_Nonnull(^CustomSecurityViewBlock)(void);
typedef CRLineView *_Nonnull(^CustomLineViewBlock)(void);
typedef void(^ConfigCellShadowBlock)(CALayer *layer);
@interface CRBoxInputCellProperty : NSObject <NSCopying>
#pragma mark - UI
/**
cell边框宽度
默认0.5
*/
@property (assign, nonatomic) CGFloat borderWidth;
/**
cell边框颜色
状态:未选中状态时
默认:[UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1]
*/
@property (copy, nonatomic) UIColor *cellBorderColorNormal;
/**
cell边框颜色
状态:选中状态时
默认:[UIColor colorWithRed:255/255.0 green:70/255.0 blue:62/255.0 alpha:1]
*/
@property (copy, nonatomic) UIColor *cellBorderColorSelected;
/**
cell边框颜色
状态:无填充文字,未选中状态时
默认与cellBorderColorFilled相同
*/
@property (copy, nonatomic) UIColor *__nullable cellBorderColorFilled;
/**
cell背景颜色
状态:无填充文字,未选中状态时
默认:[UIColor whiteColor]
*/
@property (copy, nonatomic) UIColor *cellBgColorNormal;
/**
cell背景颜色
状态:选中状态时
默认:[UIColor whiteColor]
*/
@property (copy, nonatomic) UIColor *cellBgColorSelected;
/**
cell背景颜色
状态:填充文字后,未选中状态时
默认与cellBgColorFilled相同
*/
@property (copy, nonatomic) UIColor *__nullable cellBgColorFilled;
/**
光标颜色
默认: [UIColor colorWithRed:255/255.0 green:70/255.0 blue:62/255.0 alpha:1]
*/
@property (copy, nonatomic) UIColor *cellCursorColor;
/**
光标宽度
默认: 2
*/
@property (assign, nonatomic) CGFloat cellCursorWidth;
/**
光标高度
默认: 32
*/
@property (assign, nonatomic) CGFloat cellCursorHeight;
/**
圆角
默认: 4
*/
@property (assign, nonatomic) CGFloat cornerRadius;
#pragma mark - line
/**
显示下划线
默认: NO
*/
@property (assign, nonatomic) BOOL showLine;
#pragma mark - label
/**
字体/字号
默认:[UIFont systemFontOfSize:20];
*/
@property (copy, nonatomic) UIFont *cellFont;
/**
字体颜色
默认:[UIColor blackColor];
*/
@property (copy, nonatomic) UIColor *cellTextColor;
#pragma mark - Security
/**
是否密文显示
默认NO
*/
@property (assign, nonatomic) BOOL ifShowSecurity;
/**
密文符号
默认:✱
说明只有ifShowSecurity=YES时有效
*/
@property (copy, nonatomic) NSString *securitySymbol;
/**
默认填充值
默认:空
说明:在输入框没有内容时,会显示该值。
*/
@property (copy, nonatomic) NSString *originValue;
/**
密文类型
默认CRBoxSecuritySymbolType
类型说明:
CRBoxSecuritySymbolType 符号类型根据securitySymboloriginValue的内容来显示
CRBoxSecurityCustomViewType 自定义View类型可以自定义密文状态下的图片View
*/
@property (assign, nonatomic) CRBoxSecurityType securityType;
#pragma mark - Block
/**
自定义密文View回调
*/
@property (copy, nonatomic) CustomSecurityViewBlock customSecurityViewBlock;
/**
自定义下划线回调
*/
@property (copy, nonatomic) CustomLineViewBlock customLineViewBlock;
/**
自定义阴影回调
*/
@property (copy, nonatomic) ConfigCellShadowBlock __nullable configCellShadowBlock;
#pragma mark - Test
@property (assign, nonatomic) NSInteger index;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,131 @@
//
// CRBoxInputself.m
// CaiShenYe
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import "CRBoxInputCellProperty.h"
#import <Masonry/Masonry.h>
@implementation CRBoxInputCellProperty
- (instancetype)init
{
self = [super init];
if (self) {
__weak typeof(self) weakSelf = self;
// UI
self.borderWidth = (0.5);
self.cellBorderColorNormal = [UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1];
self.cellBorderColorSelected = [UIColor colorWithRed:255/255.0 green:70/255.0 blue:62/255.0 alpha:1];
self.cellBorderColorFilled = nil;
self.cellBgColorNormal = [UIColor whiteColor];
self.cellBgColorSelected = [UIColor whiteColor];
self.cellBgColorFilled = nil;
self.cellCursorColor = [UIColor colorWithRed:255/255.0 green:70/255.0 blue:62/255.0 alpha:1];
self.cellCursorWidth = 2;
self.cellCursorHeight = 32;
self.cornerRadius = 4;
// line
self.showLine = NO;
// label
self.cellFont = [UIFont systemFontOfSize:20];
self.cellTextColor = [UIColor blackColor];
// Security
self.ifShowSecurity = NO;
self.securitySymbol = @"✱";
self.originValue = @"";
self.securityType = CRBoxSecuritySymbolType;
// Block
self.customSecurityViewBlock = ^UIView * _Nonnull{
return [weakSelf defaultCustomSecurityView];
};
self.customLineViewBlock = ^CRLineView * _Nonnull{
return [CRLineView new];
};
self.configCellShadowBlock = nil;
// Test
self.index = 0;
}
return self;
}
- (id)copyWithZone:(NSZone *)zone
{
CRBoxInputCellProperty *copy = [[self class] allocWithZone:zone];
// UI
copy.borderWidth = _borderWidth;
copy.cellBorderColorNormal = [_cellBorderColorNormal copy];
copy.cellBorderColorSelected = [_cellBorderColorSelected copy];
if (_cellBorderColorFilled) {
copy.cellBorderColorFilled = [_cellBorderColorFilled copy];
}
copy.cellBgColorNormal = [_cellBgColorNormal copy];
copy.cellBgColorSelected = [_cellBgColorSelected copy];
if (_cellBgColorFilled) {
copy.cellBgColorFilled = [_cellBgColorFilled copy];
}
copy.cellCursorColor = [_cellCursorColor copy];
copy.cellCursorWidth = _cellCursorWidth;
copy.cellCursorHeight = _cellCursorHeight;
copy.cornerRadius = _cornerRadius;
// line
copy.showLine = _showLine;
// label
copy.cellFont = [_cellFont copy];
copy.cellTextColor = [_cellTextColor copy];
// Security
copy.ifShowSecurity = _ifShowSecurity;
copy.securitySymbol = [_securitySymbol copy];
copy.originValue = [_originValue copy];
copy.securityType = _securityType;
// Block
copy.customSecurityViewBlock = [_customSecurityViewBlock copy];
copy.customLineViewBlock = [_customLineViewBlock copy];
if (_configCellShadowBlock) {
copy.configCellShadowBlock = [_configCellShadowBlock copy];
}
// Test
copy.index = _index;
return copy;
}
- (UIView *)defaultCustomSecurityView
{
UIView *customSecurityView = [UIView new];
customSecurityView.backgroundColor = [UIColor clearColor];
// circleView
static CGFloat circleViewWidth = 20;
UIView *circleView = [UIView new];
circleView.backgroundColor = [UIColor blackColor];
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;
}
@end

View File

@@ -0,0 +1,101 @@
//
// CRBoxInputView.h
// CRBoxInputView
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "CRBoxFlowLayout.h"
#import "CRBoxInputCellProperty.h"
#import "CRBoxInputCell.h"
@class CRBoxInputView;
typedef void(^TextDidChangeblock)(NSString * _Nullable text, BOOL isFinished);
@interface CRBoxInputView : UIView
/**
是否需要光标
ifNeedCursor
default: YES
*/
@property (assign, nonatomic) BOOL ifNeedCursor;
/**
验证码长度
codeLength
default: 4
*/
@property (nonatomic, assign) NSInteger codeLength;
/**
是否开启密文模式
ifNeedSecurity
default: NO
*/
@property (assign, nonatomic) BOOL ifNeedSecurity;
/**
显示密文的延时时间
securityDelay
desc: show security delay time
default: 0.3
*/
@property (assign, nonatomic) CGFloat securityDelay;
/**
键盘类型
keyBoardType
default: UIKeyboardTypeNumberPad
*/
@property (assign, nonatomic) UIKeyboardType keyBoardType;
/**
textContentType
描述: 你可以设置为 'nil' 或者 'UITextContentTypeOneTimeCode' 来自动获取短信验证码
desc: You set this 'nil' or 'UITextContentTypeOneTimeCode' to auto fill verify code.
default: nil
*/
@property (null_unspecified,nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0);
@property (copy, nonatomic) TextDidChangeblock _Nullable textDidChangeblock;
@property (strong, nonatomic) CRBoxFlowLayout * _Nullable boxFlowLayout;
@property (strong, nonatomic) CRBoxInputCellProperty * _Nullable customCellProperty;
@property (strong, nonatomic, readonly) NSString * _Nullable textValue;
@property (strong, nonatomic) UIView * _Nullable inputAccessoryView;
/**
装载数据和准备界面
desc: Load and prepareView
beginEdit: 自动开启编辑模式
default: YES
*/
- (void)loadAndPrepareView;
- (void)loadAndPrepareViewWithBeginEdit:(BOOL)beginEdit;
/**
清空输入
desc: Clear all
beginEdit: 自动开启编辑模式
default: YES
*/
- (void)clearAll;
- (void)clearAllWithBeginEdit:(BOOL)beginEdit;
- (UICollectionView *_Nullable)mainCollectionView;
// 快速设置
// Qiuck set
- (void)quickSetSecuritySymbol:(NSString *_Nullable)securitySymbol;
// 你可以在继承的子类中调用父类方法
// You can inherit and call super
- (void)initDefaultValue;
// 你可以在继承的子类中重写父类方法
// You can inherit and rewrite
- (UICollectionViewCell *_Nullable)customCollectionView:(UICollectionView *_Nullable)collectionView cellForItemAtIndexPath:(NSIndexPath *_Nullable)indexPath;
@end

View File

@@ -0,0 +1,438 @@
//
// CRBoxInputView.m
// CRBoxInputView
//
// Created by Chobits on 2019/1/3.
// Copyright © 2019 Chobits. All rights reserved.
//
#import "CRBoxInputView.h"
#import <Masonry/Masonry.h>
#import "CRBoxTextView.h"
typedef NS_ENUM(NSInteger, CRBoxTextChangeType) {
CRBoxTextChangeType_NoChange,
CRBoxTextChangeType_Insert,
CRBoxTextChangeType_Delete,
};
@interface CRBoxInputView () <UICollectionViewDataSource, UICollectionViewDelegate, UITextFieldDelegate>
{
NSInteger _oldLength;
BOOL _ifNeedBeginEdit;
}
@property (nonatomic, strong) CRBoxTextView *textView;
@property (nonatomic, strong) UICollectionView *mainCollectionView;
@property (nonatomic, strong) NSMutableArray <NSString *> *valueArr;
@property (nonatomic, strong) NSMutableArray <CRBoxInputCellProperty *> *cellPropertyArr;
@end
@implementation CRBoxInputView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self initDefaultValue];
[self addNotificationObserver];
}
return self;
}
- (instancetype)init
{
self = [super init];
if (self) {
[self initDefaultValue];
[self addNotificationObserver];
}
return self;
}
#pragma mark - Notification Observer
- (void)addNotificationObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)applicationWillResignActive:(NSNotification *)notification
{
// home
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
//
[_mainCollectionView reloadData];
}
#pragma mark - You can inherit
- (void)initDefaultValue
{
_oldLength = 0;
self.ifNeedSecurity = NO;
self.securityDelay = 0.3;
self.codeLength = 4;
self.ifNeedCursor = YES;
self.keyBoardType = UIKeyboardTypeNumberPad;
self.backgroundColor = [UIColor clearColor];
_valueArr = [NSMutableArray new];
_ifNeedBeginEdit = NO;
}
- (void)loadAndPrepareView
{
[self loadAndPrepareViewWithBeginEdit:YES];
}
- (void)loadAndPrepareViewWithBeginEdit:(BOOL)beginEdit
{
if (_codeLength<=0) {
NSAssert(NO, @"请输入大于0的验证码位数");
return;
}
[self generateCellPropertyArr];
// mainCollectionView
[self addSubview:self.mainCollectionView];
[self.mainCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsZero);
}];
// textView
[self addSubview:self.textView];
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsZero);
}];
if (beginEdit) {
[self beginEdit];
}
}
- (void)generateCellPropertyArr
{
[self.cellPropertyArr removeAllObjects];
for (int i = 0; i < self.codeLength; i++) {
[self.cellPropertyArr addObject:[self.customCellProperty copy]];
}
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
_ifNeedBeginEdit = YES;
[self.mainCollectionView reloadData];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
_ifNeedBeginEdit = NO;
[self.mainCollectionView reloadData];
}
#pragma mark - TextViewEdit
- (void)beginEdit{
[self.textView becomeFirstResponder];
}
- (void)endEdit{
[self.textView resignFirstResponder];
}
- (void)clearAll
{
[self clearAllWithBeginEdit:YES];
}
- (void)clearAllWithBeginEdit:(BOOL)beginEdit
{
_oldLength = 0;
[_valueArr removeAllObjects];
self.textView.text = @"";
[self closeAllSecurityShow];
[self.mainCollectionView reloadData];
[self triggerBlock];
if (beginEdit) {
[self beginEdit];
}
}
#pragma mark - UITextFieldDidChange
- (void)textDidChange:(UITextField *)textField{
__weak typeof(self) weakSelf = self;
NSString *verStr = textField.text;
//
verStr = [verStr stringByReplacingOccurrencesOfString:@" " withString:@""];
if (verStr.length >= _codeLength) {
verStr = [verStr substringToIndex:_codeLength];
[self endEdit];
}
textField.text = verStr;
// /
CRBoxTextChangeType boxTextChangeType = CRBoxTextChangeType_NoChange;
if (verStr.length > _oldLength) {
boxTextChangeType = CRBoxTextChangeType_Insert;
}else if (verStr.length < _oldLength){
boxTextChangeType = CRBoxTextChangeType_Delete;
}
// _valueArr
if (boxTextChangeType == CRBoxTextChangeType_Delete) {
[self setSecurityShow:NO index:_valueArr.count-1];
[_valueArr removeLastObject];
}else if (boxTextChangeType == CRBoxTextChangeType_Insert){
if (verStr.length > 0) {
if (_valueArr.count > 0) {
[self replaceValueArrToAsteriskWithIndex:_valueArr.count - 1 needEqualToCount:NO];
}
// NSString *subStr = [verStr substringWithRange:NSMakeRange(verStr.length - 1, 1)];
// [self->_valueArr addObject:subStr];
[_valueArr removeAllObjects];
[verStr enumerateSubstringsInRange:NSMakeRange(0, verStr.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
[weakSelf.valueArr addObject:substring];
}];
[self delaySecurityProcess];
}
}
[_mainCollectionView reloadData];
_oldLength = verStr.length;
[self triggerBlock];
}
#pragma mark - Control security show
- (void)setSecurityShow:(BOOL)isShow index:(NSInteger)index
{
if (index < 0) {
NSAssert(NO, @"index必须大于0");
return;
}
CRBoxInputCellProperty *cellProperty = self.cellPropertyArr[index];
cellProperty.ifShowSecurity = isShow;
}
- (void)closeAllSecurityShow
{
[self.cellPropertyArr enumerateObjectsUsingBlock:^(CRBoxInputCellProperty * _Nonnull cellProperty, NSUInteger idx, BOOL * _Nonnull stop) {
if (cellProperty.ifShowSecurity == YES) {
cellProperty.ifShowSecurity = NO;
}
}];
}
#pragma mark - Trigger block
- (void)triggerBlock
{
if (self.textDidChangeblock) {
BOOL isFinished = _valueArr.count == _codeLength ? YES : NO;
self.textDidChangeblock(_textView.text, isFinished);
}
}
#pragma mark - Asterisk
//
- (void)replaceValueArrToAsteriskWithIndex:(NSInteger)index needEqualToCount:(BOOL)needEqualToCount
{
if (!self.ifNeedSecurity) {
return;
}
if (needEqualToCount && index != _valueArr.count - 1) {
return;
}
[self setSecurityShow:YES index:index];
}
//
- (void)delaySecurityProcess
{
if (!self.ifNeedSecurity) {
return;
}
__weak typeof(self) weakSelf = self;
[self delayAfter:_securityDelay dealBlock:^{
if (self->_valueArr.count > 0) {
[weakSelf replaceValueArrToAsteriskWithIndex:self->_valueArr.count-1 needEqualToCount:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self->_mainCollectionView reloadData];
});
}
}];
}
#pragma mark - DelayBlock
- (void)delayAfter:(CGFloat)delayTime dealBlock:(void (^)(void))dealBlock
{
dispatch_time_t timer = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayTime *NSEC_PER_SEC));
dispatch_after(timer, dispatch_get_main_queue(), ^{
if (dealBlock) {
dealBlock();
}
});
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _codeLength;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
id tempCell = [self customCollectionView:collectionView cellForItemAtIndexPath:indexPath];
if ([tempCell isKindOfClass:[CRBoxInputCell class]]) {
CRBoxInputCell *cell = (CRBoxInputCell *)tempCell;
cell.ifNeedCursor = self.ifNeedCursor;
// CellProperty
CRBoxInputCellProperty *cellProperty = self.cellPropertyArr[indexPath.row];
cellProperty.index = indexPath.row;
// setOriginValue
NSUInteger focusIndex = _valueArr.count;
if (_valueArr.count > 0 && indexPath.row <= focusIndex - 1) {
cellProperty.originValue = _valueArr[indexPath.row];
}else{
cellProperty.originValue = @"";
}
cell.boxInputCellProperty = cellProperty;
if (_ifNeedBeginEdit) {
cell.selected = indexPath.row == focusIndex ? YES : NO;
}else{
cell.selected = NO;
}
}
return tempCell;
}
#pragma mark - Qiuck set
- (void)quickSetSecuritySymbol:(NSString *)securitySymbol
{
if (securitySymbol.length != 1) {
securitySymbol = @"✱";
}
self.customCellProperty.securitySymbol = securitySymbol;
}
#pragma mark - You can rewrite
- (UICollectionViewCell *)customCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CRBoxInputCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CRBoxInputCellID forIndexPath:indexPath];
return cell;
}
#pragma mark - Setter & Getter
- (UICollectionView *)mainCollectionView
{
if (!_mainCollectionView) {
_mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.boxFlowLayout];
_mainCollectionView.showsHorizontalScrollIndicator = NO;
_mainCollectionView.backgroundColor = [UIColor clearColor];
_mainCollectionView.delegate = self;
_mainCollectionView.dataSource = self;
_mainCollectionView.layer.masksToBounds = NO;
_mainCollectionView.clipsToBounds = NO;
[_mainCollectionView registerClass:[CRBoxInputCell class] forCellWithReuseIdentifier:CRBoxInputCellID];
}
return _mainCollectionView;
}
- (CRBoxFlowLayout *)boxFlowLayout
{
if (!_boxFlowLayout) {
_boxFlowLayout = [CRBoxFlowLayout new];
_boxFlowLayout.itemSize = CGSizeMake(42, 47);
}
return _boxFlowLayout;
}
- (void)setCodeLength:(NSInteger)codeLength
{
_codeLength = codeLength;
self.boxFlowLayout.itemNum = codeLength;
}
- (void)setKeyBoardType:(UIKeyboardType)keyBoardType{
_keyBoardType = keyBoardType;
self.textView.keyboardType = keyBoardType;
}
- (CRBoxTextView *)textView{
if (!_textView) {
_textView = [CRBoxTextView new];
_textView.tintColor = [UIColor clearColor];
_textView.backgroundColor = [UIColor clearColor];
_textView.textColor = [UIColor clearColor];
_textView.delegate = self;
[_textView addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
}
return _textView;
}
- (void)setTextContentType:(UITextContentType)textContentType
{
_textContentType = textContentType;
_textView.textContentType = textContentType;
}
- (CRBoxInputCellProperty *)customCellProperty
{
if (!_customCellProperty) {
_customCellProperty = [CRBoxInputCellProperty new];
}
return _customCellProperty;
}
- (NSMutableArray <CRBoxInputCellProperty *> *)cellPropertyArr
{
if (!_cellPropertyArr) {
_cellPropertyArr = [NSMutableArray new];
}
return _cellPropertyArr;
}
- (NSString *)textValue
{
return _textView.text;
}
@synthesize inputAccessoryView = _inputAccessoryView;
- (void)setInputAccessoryView:(UIView *)inputAccessoryView
{
_inputAccessoryView = inputAccessoryView;
self.textView.inputAccessoryView = _inputAccessoryView;
}
- (UIView *)inputAccessoryView
{
return _inputAccessoryView;
}
@end

View File

@@ -0,0 +1,16 @@
//
// CRBoxTextView.h
// CRBoxInputView
//
// Created by Chobits on 2019/1/3.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CRBoxTextView : UITextField
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,20 @@
//
// CRBoxTextView.m
// CRBoxInputView
//
// Created by Chobits on 2019/1/3.
//
#import "CRBoxTextView.h"
@implementation CRBoxTextView
/**
* /
*/
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return NO;
}
@end

View File

@@ -0,0 +1,21 @@
//
// CRLineView.h
// CRBoxInputView_Example
//
// Created by Chobits on 2019/6/10.
// Copyright © 2019 BearRan. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CRLineView : UIView
@property (strong, nonatomic) UIView *lineView;
- (instancetype)initWithFrame:(CGRect)frame UNAVAILABLE_ATTRIBUTE;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,48 @@
//
// CRLineView.m
// CRBoxInputView_Example
//
// Created by Chobits on 2019/6/10.
// Copyright © 2019 BearRan. All rights reserved.
//
#import "CRLineView.h"
#import <Masonry/Masonry.h>
@interface CRLineView()
{
}
@end
@implementation CRLineView
- (instancetype)init
{
self = [super init];
if (self) {
[self createUI];
}
return self;
}
- (void)createUI
{
static CGFloat sepLineViewHeight = 4;
_lineView = [UIView new];
[self addSubview:_lineView];
_lineView.backgroundColor = [UIColor blackColor];
_lineView.layer.cornerRadius = sepLineViewHeight / 2.0;
[_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(sepLineViewHeight);
make.left.right.bottom.offset(0);
}];
_lineView.layer.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.2].CGColor;
_lineView.layer.shadowOpacity = 1;
_lineView.layer.shadowOffset = CGSizeMake(0, 2);
_lineView.layer.shadowRadius = 4;
}
@end

View File

@@ -0,0 +1,21 @@
//
// CRSecrectImageView.h
// CRBoxInputView_Example
//
// Created by Chobits on 2019/6/10.
// Copyright © 2019 BearRan. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CRSecrectImageView : UIView
@property (strong, nonatomic) UIImage *image;
@property (assign, nonatomic) CGFloat imageWidth;
@property (assign, nonatomic) CGFloat imageHeight;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,65 @@
//
// CRSecrectImageView.m
// CRBoxInputView_Example
//
// Created by Chobits on 2019/6/10.
// Copyright © 2019 BearRan. All rights reserved.
//
#import "CRSecrectImageView.h"
#import <Masonry/Masonry.h>
@interface CRSecrectImageView()
{
UIImageView *_lockImgView;
}
@end
@implementation CRSecrectImageView
- (instancetype)init
{
self = [super init];
if (self) {
[self createUI];
}
return self;
}
- (void)createUI
{
_lockImgView = [UIImageView new];
_lockImgView.image = [UIImage imageNamed:@"smallLock"];
[self addSubview:_lockImgView];
[_lockImgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.offset(0);
make.centerY.offset(0);
make.width.mas_equalTo(23);
make.height.mas_equalTo(27);
}];
}
#pragma mark - Setter & Getter
- (void)setImage:(UIImage *)image
{
_image = image;
_lockImgView.image = image;
}
- (void)setImageWidth:(CGFloat)imageWidth
{
_imageWidth = imageWidth;
[_lockImgView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(imageWidth);
}];
}
- (void)setImageHeight:(CGFloat)imageHeight
{
_imageHeight = imageHeight;
[_lockImgView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(imageHeight);
}];
}
@end

473
Pods/CRBoxInputView/README.md generated Executable file
View File

@@ -0,0 +1,473 @@
<a id="Header_Start"></a> ![CRBoxInputViewHeadImg.png](/ReadmeResources/HeadImg.png "CRBoxInputViewHeadImg.png")
[![CI Status](https://img.shields.io/travis/CRAnimation/CRBoxInputView.svg?style=flat)](https://travis-ci.org/CRAnimation/CRBoxInputView)
[![Version](https://img.shields.io/cocoapods/v/CRBoxInputView.svg?style=flat)](https://cocoapods.org/pods/CRBoxInputView)
[![License](https://img.shields.io/cocoapods/l/CRBoxInputView.svg?style=flat)](https://cocoapods.org/pods/CRBoxInputView)
[![Platform](https://img.shields.io/cocoapods/p/CRBoxInputView.svg?style=flat)](https://cocoapods.org/pods/CRBoxInputView)
### [中文文档](https://github.com/CRAnimation/CRBoxInputView#Header_Start) [/ English Document](https://github.com/CRAnimation/CRBoxInputView/blob/master/README_en.md#Header_Start)
## 组件特点
- 支持iOS12短信验证码自动填充
- 支持`Masonry`
- 支持密文显示
- 支持自定义密文图片/view
- 支持iOS8及以上操作系统
> 该组件适用于短信验证码,密码输入框,手机号码输入框这些场景。<br/>希望你可以喜欢!
## 重大更新!!!
从1.0.0版本开始,无需通过继承的方式使用。通过设置`CRBoxInputCellProperty`中的对应Block即可快速自定义需求。
``` objc
customSecurityViewBlock //自定义密文View
customLineViewBlock //自定义下划线
configCellShadowBlock //自定义阴影
```
>此更新兼容1.0.0之前的版本
## Pod安装
CRBoxInputView 可以通过 [CocoaPods](https://cocoapods.org). 来安装, 只需简单的在你的 Podfile 中添加如下代码:
```ruby
pod 'CRBoxInputView', '1.0.2'
```
## 示列
下载源代码后可以从Example目录中执行 `pod install`然后运行Demo。
![iPhone 8 Copy 2.png](/ReadmeResources/ScreenShoot1.png "iPhone 8 Copy 2.png")
## 快速指南
| 类型 | 示例图片 |
| :-------------: | :-------------: |
| [Base](#Anchor_Base) | ![Normal.png](/ReadmeResources/1Normal.png "Normal.png") |
| [CustomBox](#Anchor_CustomBox) | ![CustomBox.png](/ReadmeResources/2CustomBox.png "CustomBox.png") |
| [Line](#Anchor_Line) | ![Line.png](/ReadmeResources/3Line.png "Line.png") |
| [SecretSymbol](#Anchor_SecretSymbol) | ![SecretSymbol.png](/ReadmeResources/4SecretSymbol.png "SecretSymbol.png") |
| [SecretImage](#Anchor_SecretImage) | ![SecretImage.png](/ReadmeResources/5SecretImage.png "SecretImage.png") |
| [SecretView](#Anchor_SecretView) | ![SecretView.png](/ReadmeResources/6SecretView.png "SecretView.png") |
## 使用说明
### <a id="Anchor_Base"></a>Base
![Normal.png](/ReadmeResources/1Normal.png "Normal.png")
``` objc
CRBoxInputView *boxInputView = [[CRBoxInputView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
boxInputView.codeLength = 4;// 不设置时默认4
boxInputView.keyBoardType = UIKeyboardTypeNumberPad;// 不设置时默认UIKeyboardTypeNumberPad
[boxInputView loadAndPrepareViewWithBeginEdit:YES]; // BeginEdit:是否自动启用编辑模式
[self.view addSubview:boxInputView];
// 获取值
// 方法1, 当输入文字变化时触发回调block
boxInputView.textDidChangeblock = ^(NSString *text, BOOL isFinished) {
NSLog(@"text:%@", text);
};
// 方法2, 普通的只读属性
NSLog(@"textValue:%@", boxInputView.textValue);
// 清空
[boxInputView clearAllWithBeginEdit:YES]; // BeginEdit:清空后是否自动启用编辑模式
```
<br/>
### <a id="Anchor_CustomBox"></a>CustomBox
![CustomBox.png](/ReadmeResources/2CustomBox.png "CustomBox.png")
``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.cellBgColorNormal = color_FFECEC;
cellProperty.cellBgColorSelected = [UIColor whiteColor];
cellProperty.cellCursorColor = color_master;
cellProperty.cellCursorWidth = 2;
cellProperty.cellCursorHeight = 30;
cellProperty.cornerRadius = 4;
cellProperty.borderWidth = 0;
cellProperty.cellFont = [UIFont boldSystemFontOfSize:24];
cellProperty.cellTextColor = color_master;
cellProperty.configCellShadowBlock = ^(CALayer * _Nonnull layer) {
layer.shadowColor = [color_master colorWithAlphaComponent:0.2].CGColor;
layer.shadowOpacity = 1;
layer.shadowOffset = CGSizeMake(0, 2);
layer.shadowRadius = 4;
};
CRBoxInputView *boxInputView = [CRBoxInputView new];
boxInputView.boxFlowLayout.itemSize = CGSizeMake(50, 50);
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
```
<br/>
### <a id="Anchor_Line"></a>Line
![Line.png](/ReadmeResources/3Line.png "Line.png")
``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.showLine = YES; //必需
cellProperty.customLineViewBlock = ^CRLineView * _Nonnull{
CRLineView *lineView = [CRLineView new];
lineView.lineView.backgroundColor = color_master;
[lineView.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(4);
make.left.right.bottom.offset(0);
}];
return lineView;
}; //可选
CRBoxInputView *boxInputView = [CRBoxInputView new];
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
```
<br/>
### <a id="Anchor_SecretSymbol"></a>SecretSymbol
![SecretSymbol.png](/ReadmeResources/4SecretSymbol.png "SecretSymbol.png")
``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.securitySymbol = @"*"; //可选
CRBoxInputView *boxInputView = [CRBoxInputView new];
boxInputView.ifNeedSecurity = YES; //必需
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
```
<br/>
### <a id="Anchor_SecretImage"></a>SecretImage
![SecretImage.png](/ReadmeResources/5SecretImage.png "SecretImage.png")
``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.securityType = CRBoxSecurityCustomViewType; //必需
cellProperty.customSecurityViewBlock = ^UIView * _Nonnull{
CRSecrectImageView *secrectImageView = [CRSecrectImageView new];
secrectImageView.image = [UIImage imageNamed:@"smallLock"];
secrectImageView.imageWidth = 23;
secrectImageView.imageHeight = 27;
return secrectImageView;
}; //必需
CRBoxInputView *boxInputView = [CRBoxInputView new];
boxInputView.ifNeedSecurity = YES; //必需
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
```
<br/>
### <a id="Anchor_SecretView"></a>SecretView
![SecretView.png](/ReadmeResources/6SecretView.png "SecretView.png")
``` objc
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
cellProperty.securityType = CRBoxSecurityCustomViewType; //必需
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;
}; //可选
CRBoxInputView *boxInputView = [CRBoxInputView new];
boxInputView.ifNeedSecurity = YES; //必需
boxInputView.customCellProperty = cellProperty;
[boxInputView loadAndPrepareViewWithBeginEdit:YES];
```
<br/>
## 属性和方法
`CRBoxInputCellProperty` class
``` objc
#pragma mark - UI
/**
cell边框宽度
默认0.5
*/
@property (assign, nonatomic) CGFloat borderWidth;
/**
cell边框颜色
状态:未选中状态时
默认:[UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1]
*/
@property (copy, nonatomic) UIColor *cellBorderColorNormal;
/**
cell边框颜色
状态:选中状态时
默认:[UIColor colorWithRed:255/255.0 green:70/255.0 blue:62/255.0 alpha:1]
*/
@property (copy, nonatomic) UIColor *cellBorderColorSelected;
/**
cell边框颜色
状态:无填充文字,未选中状态时
默认与cellBorderColorFilled相同
*/
@property (copy, nonatomic) UIColor *__nullable cellBorderColorFilled;
/**
cell背景颜色
状态:无填充文字,未选中状态时
默认:[UIColor whiteColor]
*/
@property (copy, nonatomic) UIColor *cellBgColorNormal;
/**
cell背景颜色
状态:选中状态时
默认:[UIColor whiteColor]
*/
@property (copy, nonatomic) UIColor *cellBgColorSelected;
/**
cell背景颜色
状态:填充文字后,未选中状态时
默认与cellBgColorFilled相同
*/
@property (copy, nonatomic) UIColor *__nullable cellBgColorFilled;
/**
光标颜色
默认: [UIColor colorWithRed:255/255.0 green:70/255.0 blue:62/255.0 alpha:1]
*/
@property (copy, nonatomic) UIColor *cellCursorColor;
/**
光标宽度
默认: 2
*/
@property (assign, nonatomic) CGFloat cellCursorWidth;
/**
光标高度
默认: 32
*/
@property (assign, nonatomic) CGFloat cellCursorHeight;
/**
圆角
默认: 4
*/
@property (assign, nonatomic) CGFloat cornerRadius;
#pragma mark - line
/**
显示下划线
默认: NO
*/
@property (assign, nonatomic) BOOL showLine;
#pragma mark - label
/**
字体/字号
默认:[UIFont systemFontOfSize:20];
*/
@property (copy, nonatomic) UIFont *cellFont;
/**
字体颜色
默认:[UIColor blackColor];
*/
@property (copy, nonatomic) UIColor *cellTextColor;
#pragma mark - Security
/**
是否密文显示
默认NO
*/
@property (assign, nonatomic) BOOL ifShowSecurity;
/**
密文符号
默认:✱
说明只有ifShowSecurity=YES时有效
*/
@property (copy, nonatomic) NSString *securitySymbol;
/**
默认填充值
默认:空
说明:在输入框没有内容时,会显示该值。
*/
@property (copy, nonatomic) NSString *originValue;
/**
密文类型
默认CRBoxSecuritySymbolType
类型说明:
CRBoxSecuritySymbolType 符号类型根据securitySymboloriginValue的内容来显示
CRBoxSecurityCustomViewType 自定义View类型可以自定义密文状态下的图片View
*/
@property (assign, nonatomic) CRBoxSecurityType securityType;
#pragma mark - Block
/**
自定义密文View回调
*/
@property (copy, nonatomic) CustomSecurityViewBlock customSecurityViewBlock;
/**
自定义下划线回调
*/
@property (copy, nonatomic) CustomLineViewBlock customLineViewBlock;
/**
自定义阴影回调
*/
@property (copy, nonatomic) ConfigCellShadowBlock __nullable configCellShadowBlock;
```
`CRBoxFlowLayout` class
``` objc
/** 是否需要等间距
* default: YES
*/
@property (assign, nonatomic) BOOL ifNeedEqualGap;
@property (assign, nonatomic) NSInteger itemNum;
```
`CRBoxInputView` class
``` objc
/**
是否需要光标
ifNeedCursor
default: YES
*/
@property (assign, nonatomic) BOOL ifNeedCursor;
/**
验证码长度
codeLength
default: 4
*/
@property (nonatomic, assign) NSInteger codeLength;
/**
是否开启密文模式
ifNeedSecurity
default: NO
*/
@property (assign, nonatomic) BOOL ifNeedSecurity;
/**
显示密文的延时时间
securityDelay
desc: show security delay time
default: 0.3
*/
@property (assign, nonatomic) CGFloat securityDelay;
/**
键盘类型
keyBoardType
default: UIKeyboardTypeNumberPad
*/
@property (assign, nonatomic) UIKeyboardType keyBoardType;
/**
textContentType
描述: 你可以设置为 'nil' 或者 'UITextContentTypeOneTimeCode' 来自动获取短信验证码
desc: You set this 'nil' or 'UITextContentTypeOneTimeCode' to auto fill verify code.
default: nil
*/
@property (null_unspecified,nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0);
@property (copy, nonatomic) TextDidChangeblock _Nullable textDidChangeblock;
@property (strong, nonatomic) CRBoxFlowLayout * _Nullable boxFlowLayout;
@property (strong, nonatomic) CRBoxInputCellProperty * _Nullable customCellProperty;
@property (strong, nonatomic, readonly) NSString * _Nullable textValue;
@property (strong, nonatomic) UIView * _Nullable inputAccessoryView;
/**
装载数据和准备界面
desc: Load and prepareView
beginEdit: 自动开启编辑模式
default: YES
*/
- (void)loadAndPrepareView;
- (void)loadAndPrepareViewWithBeginEdit:(BOOL)beginEdit;
/**
清空输入
desc: Clear all
beginEdit: 自动开启编辑模式
default: YES
*/
- (void)clearAll;
- (void)clearAllWithBeginEdit:(BOOL)beginEdit;
- (UICollectionView *_Nullable)mainCollectionView;
// 快速设置
// Qiuck set
- (void)quickSetSecuritySymbol:(NSString *_Nullable)securitySymbol;
// 你可以在继承的子类中调用父类方法
// You can inherit and call super
- (void)initDefaultValue;
// 你可以在继承的子类中重写父类方法
// You can inherit and rewrite
- (UICollectionViewCell *_Nullable)customCollectionView:(UICollectionView *_Nullable)collectionView cellForItemAtIndexPath:(NSIndexPath *_Nullable)indexPath;
```
`CRBoxInputCell` class
``` objc
// 你可以在继承的子类中重写父类方法
// You can inherit and rewrite
- (UIView *)createCustomSecurityView;
```
## 其他问题
- [pod search 搜索不到库(已解决)](https://github.com/CRAnimation/CRBoxInputView/issues/1 "pod search 搜索不到库")
- [pod 安装失败, [!] Unable to find a specification for CRBoxInputView已解决](https://github.com/CRAnimation/CRBoxInputView/issues/2 "pod 安装失败, [!] Unable to find a specification for CRBoxInputView")
## 作者
BearRan, 648070256@qq.com
## 反馈
如果你在使用这个控件时遇到了问题可以通过E-mail告诉我或者为此开一个issuse。
## License
CRBoxInputView is available under the MIT license. See the LICENSE file for more info.