TOPasscodeInputField.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // TOPasscodeInputField.h
  3. //
  4. // Copyright 2017 Timothy Oliver. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  21. // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #import <UIKit/UIKit.h>
  23. #import "TOPasscodeFixedInputView.h"
  24. #import "TOPasscodeVariableInputView.h"
  25. NS_ASSUME_NONNULL_BEGIN
  26. typedef NS_ENUM(NSInteger, TOPasscodeInputFieldStyle) {
  27. TOPasscodeInputFieldStyleFixed, // The passcode explicitly requires a specific number of characters (Shows hollow circles)
  28. TOPasscodeInputFieldStyleVariable // The passcode can be any arbitrary number of characters (Shows an empty rectangle)
  29. };
  30. /**
  31. An abstract input view capable of receiving different types of passcodes.
  32. When a fixed character passcode is specified, the view shows a row of circles.
  33. When a variable passcode is specified, a rounded rectangle is shown.
  34. */
  35. @interface TOPasscodeInputField : UIView <UIKeyInput>
  36. /* The visual effects view used to control the vibrancy of the input field */
  37. @property (nonatomic, strong, readonly) UIVisualEffectView *visualEffectView;
  38. /* The input style of this control */
  39. @property (nonatomic, assign) TOPasscodeInputFieldStyle style;
  40. /* A row of hollow circles at a preset length. Valid only when `style` is set to `fixed` */
  41. @property (nonatomic, readonly, nullable) TOPasscodeFixedInputView *fixedInputView;
  42. /* A rounded rectangle representing a passcode of arbitrary length. Valid only when `style` is set to `variable`. */
  43. @property (nonatomic, readonly, nullable) TOPasscodeVariableInputView *variableInputView;
  44. /* The 'submit' button shown when `showSubmitButton` is true. */
  45. @property (nonatomic, readonly, nullable) UIButton *submitButton;
  46. /* Shows an 'OK' button next to the view when characters have been added. */
  47. @property (nonatomic, assign) BOOL showSubmitButton;
  48. /* The amount of spacing between the 'OK' button and the passcode field */
  49. @property (nonatomic, assign) CGFloat submitButtonSpacing;
  50. /* The amount of spacing between the 'OK' button and the passcode field */
  51. @property (nonatomic, assign) CGFloat submitButtonVerticalSpacing;
  52. /* The font size of the submit button */
  53. @property (nonatomic, assign) CGFloat submitButtonFontSize;
  54. /* The current passcode entered into this view */
  55. @property (nonatomic, copy, nullable) NSString *passcode;
  56. /* If this view is directly receiving input, this can change the `UIKeyboard` appearance. */
  57. @property (nonatomic, assign) UIKeyboardAppearance keyboardAppearance;
  58. /* The type of button used for the 'Done' button in the keyboard */
  59. @property(nonatomic, assign) UIReturnKeyType returnKeyType;
  60. /* The alpha value of the views in this view (For tranclucent styling) */
  61. @property (nonatomic, assign) CGFloat contentAlpha;
  62. /* Whether the view may be tapped to enable character input (Default is NO) */
  63. @property (nonatomic, assign) BOOL enabled;
  64. /** Called when the number of digits has been entered, or the user tapped 'Done' on the keyboard */
  65. @property (nonatomic, copy) void (^passcodeCompletedHandler)(NSString *code);
  66. /** Horizontal layout. The 'OK' button will be placed under the text field */
  67. @property (nonatomic, assign) BOOL horizontalLayout;
  68. /* Init with the target length needed for this passcode */
  69. - (instancetype)initWithStyle:(TOPasscodeInputFieldStyle)style;
  70. /* Replace the passcode with this one, and animate the transition. */
  71. - (void)setPasscode:(nullable NSString *)passcode animated:(BOOL)animated;
  72. /* Add additional characters to the end of the passcode, and animate if desired. */
  73. - (void)appendPasscodeCharacters:(NSString *)characters animated:(BOOL)animated;
  74. /* Delete a number of characters from the end, animated if desired. */
  75. - (void)deletePasscodeCharactersOfCount:(NSInteger)deleteCount animated:(BOOL)animated;
  76. /* Plays a shaking animation and resets the passcode back to empty */
  77. - (void)resetPasscodeAnimated:(BOOL)animated playImpact:(BOOL)impact;
  78. /* Animates the OK button changing location. */
  79. - (void)setHorizontalLayout:(BOOL)horizontalLayout animated:(BOOL)animated duration:(CGFloat)duration;
  80. @end
  81. NS_ASSUME_NONNULL_END