YMCaptchaTextView.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // YMCaptchaTextView.h
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2023/5/5.
  6. //
  7. #import <UIKit/UIKit.h>
  8. #import "YMCaptchaTextFlowLayout.h"
  9. #import "YMCaptchaTextCell.h"
  10. #import "YMCaptchaTextCellProperty.h"
  11. @class YMCaptchaTextView;
  12. typedef NS_ENUM(NSInteger, YMCaptchaTextEditStatus) {
  13. YMCaptchaTextEditStatus_Idle,
  14. YMCaptchaTextEditStatus_BeginEdit,
  15. YMCaptchaTextEditStatus_EndEdit,
  16. };
  17. typedef NS_ENUM(NSInteger, YMCaptchaTextType) {
  18. /// 数字
  19. YMCaptchaTextType_Number,
  20. /// 普通(不作任何处理)
  21. YMCaptchaTextType_Normal,
  22. /// 自定义正则(此时需要设置customInputRegex)
  23. YMCaptchaTextType_Regex,
  24. };
  25. typedef void(^TextDidChangeblock)(NSString * _Nullable text, BOOL isFinished);
  26. typedef void(^TextEditStatusChangeblock)(YMCaptchaTextEditStatus editStatus);
  27. typedef NSString *_Nullable(^TextCustomProcessblock)(NSString * _Nullable text);
  28. @interface YMCaptchaTextView : UIView
  29. /**
  30. 是否需要光标
  31. ifNeedCursor
  32. default: YES
  33. */
  34. @property (nonatomic, assign) BOOL ifNeedCursor;
  35. /**
  36. 验证码长度
  37. codeLength
  38. default: 4
  39. */
  40. @property (nonatomic, assign, readonly) NSInteger codeLength; //If you want to set codeLength, please use `- (instancetype)initWithCodeLength:(NSInteger)codeLength, or - (void)resetCodeLength:(NSInteger)codeLength beginEdit:(BOOL)beginEdit` in CRBoxInputView.
  41. /**
  42. 是否开启密文模式
  43. 描述:你可以在任何时候修改该属性,并且已经存在的文字会自动刷新。
  44. ifNeedSecurity
  45. desc: You can change this property anytime. And the existing texts can be refreshed automatically.
  46. default: NO
  47. */
  48. @property (nonatomic, assign) BOOL ifNeedSecurity;
  49. /**
  50. 显示密文的延时时间
  51. securityDelay
  52. desc: show security delay time
  53. default: 0.3
  54. */
  55. @property (nonatomic, assign) CGFloat securityDelay;
  56. /**
  57. 键盘类型
  58. keyBoardType
  59. default: UIKeyboardTypeNumberPad
  60. */
  61. @property (nonatomic, assign) UIKeyboardType keyBoardType;
  62. /**
  63. 输入样式
  64. TextType
  65. default: YMCaptchaTextType_Number
  66. */
  67. @property (nonatomic, assign) YMCaptchaTextType textType;
  68. /**
  69. 自定义正则匹配输入内容
  70. customInputRegex
  71. default: @""
  72. 当inputType == YMCaptchaTextType_Regex时才会生效
  73. */
  74. @property (nonatomic, copy) NSString * _Nullable customInputRegex;
  75. /**
  76. textContentType
  77. 描述: 你可以设置为 'nil' 或者 'UITextContentTypeOneTimeCode' 来自动获取短信验证码
  78. desc: You set this 'nil' or 'UITextContentTypeOneTimeCode' to auto fill verify code.
  79. default: nil
  80. */
  81. @property (null_unspecified, nonatomic, copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0);
  82. /**
  83. 占位字符填充值
  84. 说明:在对应的输入框没有内容时,会显示该值。
  85. 默认:nil
  86. */
  87. @property (nonatomic, strong) NSString * _Nullable placeholderText;
  88. /**
  89. 弹出键盘时,是否清空所有输入
  90. 只有在输入的字数等于codeLength时,生效
  91. default: NO
  92. */
  93. @property (nonatomic, assign) BOOL ifClearAllInBeginEditing;
  94. @property (nonatomic, copy) TextDidChangeblock _Nullable textDidChangeblock;
  95. @property (nonatomic, copy) TextEditStatusChangeblock _Nullable textEditStatusChangeblock;
  96. /// 文本自定义处理
  97. @property (nonatomic, copy) TextCustomProcessblock _Nullable textCustomProcessblock;
  98. @property (nonatomic, strong) YMCaptchaTextFlowLayout * _Nullable captchaTextFlowLayout;
  99. @property (nonatomic, strong) YMCaptchaTextCellProperty * _Nullable customCellProperty;
  100. @property (nonatomic, strong) UIView * _Nullable inputAccessoryView;
  101. @property (nonatomic, strong, readonly) NSString * _Nullable textValue;
  102. /**
  103. 装载数据和准备界面
  104. desc: Load and prepareView
  105. beginEdit: 自动开启编辑模式
  106. default: YES
  107. */
  108. - (void)loadAndPrepareView;
  109. - (void)loadAndPrepareViewWithBeginEdit:(BOOL)beginEdit;
  110. /**
  111. 重载输入的数据(用来设置预设数据)
  112. desc:Reload string. (You can use this function to set deault value)
  113. */
  114. - (void)reloadInputString:(NSString *_Nullable)value;
  115. /**
  116. 清空输入
  117. desc: Clear all
  118. beginEdit: 自动开启编辑模式
  119. default: YES
  120. */
  121. - (void)clearAll;
  122. - (void)clearAllWithBeginEdit:(BOOL)beginEdit;
  123. - (UICollectionView *_Nullable)mainCollectionView;
  124. // 快速设置
  125. // Qiuck set
  126. - (void)quickSetSecuritySymbol:(NSString *_Nullable)securitySymbol;
  127. // 你可以在继承的子类中调用父类方法
  128. // You can inherit and call super
  129. - (void)initDefaultValue;
  130. // 你可以在继承的子类中重写父类方法
  131. // You can inherit and rewrite
  132. - (UICollectionViewCell *_Nullable)customCollectionView:(UICollectionView *_Nullable)collectionView cellForItemAtIndexPath:(NSIndexPath *_Nullable)indexPath;
  133. // code Length 调整
  134. - (void)resetCodeLength:(NSInteger)codeLength beginEdit:(BOOL)beginEdit;
  135. // Init
  136. - (instancetype _Nullable )initWithCodeLength:(NSInteger)codeLength;
  137. @end