BTUIKFormField.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #import <UIKit/UIKit.h>
  2. #import "BTUIKTextField.h"
  3. @protocol BTUIKFormFieldDelegate;
  4. /// @class A UIView containing a BTUIKTextField and other elements to be displayed as a form field. This class is meant to be extended but can be used as is for other generic form fields.
  5. @interface BTUIKFormField : UIView <UITextFieldDelegate, UIKeyInput>
  6. /// The delegate for this form field
  7. @property (nonatomic, weak) id<BTUIKFormFieldDelegate> delegate;
  8. /// Whether to vibrate on invalid input
  9. @property (nonatomic, assign) BOOL vibrateOnInvalidInput;
  10. /// Is the form field currently valid, this does not imply it is completed
  11. @property (nonatomic, assign, readonly) BOOL valid;
  12. /// Is the entry completed
  13. @property (nonatomic, assign, readonly) BOOL entryComplete;
  14. /// Whether to display as valid
  15. @property (nonatomic, assign) BOOL displayAsValid;
  16. /// Should show a bottom border
  17. @property (nonatomic, assign) BOOL bottomBorder;
  18. /// Should show a top border
  19. @property (nonatomic, assign) BOOL topBorder;
  20. /// Should show an inter bottom border
  21. @property (nonatomic, assign) BOOL interFieldBorder;
  22. /// Whether to allow backspace
  23. @property (nonatomic, assign, readwrite) BOOL backspace;
  24. /// The text displayed by the field
  25. @property (nonatomic, copy) NSString *text;
  26. /// The text field
  27. @property (nonatomic, strong) BTUIKTextField* textField;
  28. /// The label
  29. @property (nonatomic, strong) UILabel* formLabel;
  30. /// The accessory view shown opposite the label
  31. @property (nonatomic, strong) UIView *accessoryView;
  32. /// Updates the appearance of the form field (e.g if it is invalid it will appear with error colors)
  33. - (void)updateAppearance;
  34. /// Update constraints
  35. - (void)updateConstraints;
  36. /// Set the accessory view visibility
  37. /// @param hidden The desired hidden state
  38. /// @param animated Whether to animate when updating the visibility
  39. - (void)setAccessoryViewHidden:(BOOL)hidden animated:(BOOL)animated;
  40. /// To be implemented by subclasses. Otherwise does nothing.
  41. - (void)resetFormField;
  42. @end
  43. /// @protocol Required by the delegate
  44. @protocol BTUIKFormFieldDelegate <NSObject>
  45. /// Called when the content changes
  46. - (void)formFieldDidChange:(BTUIKFormField *)formField;
  47. @optional
  48. /// Use to override the default behavior or returning `YES` for textFieldShouldReturn.
  49. - (BOOL)formFieldShouldReturn:(BTUIKFormField *)formField;
  50. /// Did begin editing
  51. - (void)formFieldDidBeginEditing:(BTUIKFormField *)formField;
  52. /// Did end editing
  53. - (void)formFieldDidEndEditing:(BTUIKFormField *)formField;
  54. @end