BTUIKSecurityCodeFormField.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #import "BTUIKSecurityCodeFormField.h"
  2. #import "BTUIKTextField.h"
  3. #import "BTUIKInputAccessoryToolbar.h"
  4. #import "BTUIKLocalizedString.h"
  5. @interface BTUIKSecurityCodeFormField ()
  6. @end
  7. @implementation BTUIKSecurityCodeFormField
  8. - (instancetype)initWithFrame:(CGRect)frame {
  9. self = [super initWithFrame:frame];
  10. if (self) {
  11. self.textField.accessibilityLabel = BTUIKLocalizedString(SECURITY_CODE_LABEL);
  12. self.formLabel.text = BTUIKLocalizedString(SECURITY_CODE_LABEL);
  13. self.textField.placeholder = BTUIKLocalizedString(CVV_FIELD_PLACEHOLDER);
  14. self.textField.keyboardType = UIKeyboardTypeNumberPad;
  15. }
  16. return self;
  17. }
  18. #pragma mark - Custom accessors
  19. - (BOOL)valid {
  20. return self.securityCode.length >= 3;
  21. }
  22. - (NSString *)securityCode {
  23. return self.textField.text;
  24. }
  25. #pragma mark UITextFieldDelegate
  26. - (void)fieldContentDidChange {
  27. [self.delegate formFieldDidChange:self];
  28. [self updateAppearance];
  29. }
  30. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  31. [super textFieldDidBeginEditing:textField];
  32. [self updateAppearance];
  33. }
  34. - (void)textFieldDidEndEditing:(UITextField *)textField {
  35. [super textFieldDidEndEditing:textField];
  36. [self updateAppearance];
  37. }
  38. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  39. return textField.text.length - range.length + string.length <= 4;
  40. }
  41. @end