SLKTextInputbar.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // SlackTextViewController
  3. // https://github.com/slackhq/SlackTextViewController
  4. //
  5. // Copyright 2014-2016 Slack Technologies, Inc.
  6. // Licence: MIT-Licence
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "SLKVisibleViewProtocol.h"
  10. @class SLKTextView;
  11. @class SLKInputAccessoryView;
  12. typedef NS_ENUM(NSUInteger, SLKCounterStyle) {
  13. SLKCounterStyleNone,
  14. SLKCounterStyleSplit,
  15. SLKCounterStyleCountdown,
  16. SLKCounterStyleCountdownReversed,
  17. SLKCounterStyleLimitExceeded
  18. };
  19. typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
  20. SLKCounterPositionTop,
  21. SLKCounterPositionBottom
  22. };
  23. NS_ASSUME_NONNULL_BEGIN
  24. UIKIT_EXTERN NSString * const SLKTextInputbarContentSizeDidChangeNotification;
  25. /** @name A custom tool bar encapsulating messaging controls. */
  26. @interface SLKTextInputbar : UIToolbar
  27. /** The centered text input view.
  28. The maximum number of lines is configured by default, to best fit each devices dimensions.
  29. For iPhone 4 (<=480pts): 4 lines
  30. For iPhone 5 & 6 (>=568pts): 6 lines
  31. For iPad (>=768pts): 8 lines
  32. */
  33. @property (nonatomic, readonly, strong) SLKTextView *textView;
  34. /** Optional view to host outlets under the text view, adjusting its height based on its subviews. Non-visible by default. Subviews' layout should be configured using auto-layout as well. */
  35. @property (nonatomic, readonly, strong) UIView *contentView;
  36. /** The custom input accessory view, used as empty achor view to detect the keyboard frame. */
  37. @property (nonatomic, readonly, strong) SLKInputAccessoryView *inputAccessoryView;
  38. /** The left action button action. */
  39. @property (nonatomic, strong) UIButton *leftButton;
  40. /** The right action button action. */
  41. @property (nonatomic, strong) UIButton *rightButton;
  42. /** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
  43. @property (nonatomic, readwrite) BOOL autoHideRightButton;
  44. /** YES if animations should have bouncy effects. Default is YES. */
  45. @property (nonatomic, assign) BOOL bounces;
  46. /** The inner padding to use when laying out content in the view. Default is {5, 8, 5, 8}. */
  47. @property (nonatomic, assign) UIEdgeInsets contentInset;
  48. /** The minimum height based on the intrinsic content size's. */
  49. @property (nonatomic, readonly) CGFloat minimumInputbarHeight;
  50. /** The most appropriate height calculated based on the amount of lines of text and other factors. */
  51. @property (nonatomic, readonly) CGFloat appropriateHeight;
  52. /** View that is displayed above the inputbar to show typing indicators */
  53. @property (nonatomic, strong) UIView <SLKVisibleViewProtocol> *typingView;
  54. #pragma mark - Initialization
  55. ///------------------------------------------------
  56. /// @name Initialization
  57. ///------------------------------------------------
  58. /**
  59. Initializes a text input bar with a class to be used for the text view
  60. @param textViewClass The class to be used when creating the text view. May be nil. If provided, the class must be a subclass of SLKTextView
  61. @return An initialized SLKTextInputbar object or nil if the object could not be created.
  62. */
  63. - (instancetype)initWithTextViewClass:(Class)textViewClass;
  64. - (instancetype)initWithTextViewClass:(Class)textViewClass withTypingIndicatorViewClass:(Class)typingIndicatorClass;
  65. #pragma mark - Text Editing
  66. ///------------------------------------------------
  67. /// @name Text Editing
  68. ///------------------------------------------------
  69. /** The view displayed on top if the text input bar, containing the button outlets, when editing is enabled. */
  70. @property (nonatomic, strong) UIView *editorContentView;
  71. /** The title label displayed in the middle of the accessoryView. */
  72. @property (nonatomic, strong) UILabel *editorTitle;
  73. /** The 'cancel' button displayed left in the accessoryView. */
  74. @property (nonatomic, strong) UIButton *editorLeftButton;
  75. /** The 'accept' button displayed right in the accessoryView. */
  76. @property (nonatomic, strong) UIButton *editorRightButton;
  77. /** The accessory view's maximum height. Default is 38 pts. */
  78. @property (nonatomic, assign) CGFloat editorContentViewHeight;
  79. /** A Boolean value indicating whether the control is in edit mode. */
  80. @property (nonatomic, getter = isEditing) BOOL editing;
  81. /**
  82. Verifies if the text can be edited.
  83. @param text The text to be edited.
  84. @return YES if the text is editable.
  85. */
  86. - (BOOL)canEditText:(NSString *)text;
  87. /**
  88. Begins editing the text, by updating the 'editing' flag and the view constraints.
  89. */
  90. - (void)beginTextEditing;
  91. /**
  92. End editing the text, by updating the 'editing' flag and the view constraints.
  93. */
  94. - (void)endTextEdition;
  95. #pragma mark - Text Counting
  96. ///------------------------------------------------
  97. /// @name Text Counting
  98. ///------------------------------------------------
  99. /** The label used to display the character counts. */
  100. @property (nonatomic, readonly) UILabel *charCountLabel;
  101. /** The maximum character count allowed. If larger than 0, a character count label will be displayed on top of the right button. Default is 0, which means limitless.*/
  102. @property (nonatomic, readwrite) NSUInteger maxCharCount;
  103. /** The character counter formatting. Ignored if maxCharCount is 0. Default is None. */
  104. @property (nonatomic, assign) SLKCounterStyle counterStyle;
  105. /** The character counter layout style. Ignored if maxCharCount is 0. Default is SLKCounterPositionTop. */
  106. @property (nonatomic, assign) SLKCounterPosition counterPosition;
  107. /** YES if the maxmimum character count has been exceeded. */
  108. @property (nonatomic, readonly) BOOL limitExceeded;
  109. /** The normal color used for character counter label. Default is lightGrayColor. */
  110. @property (nonatomic, strong, readwrite) UIColor *charCountLabelNormalColor;
  111. /** The color used for character counter label when it has exceeded the limit. Default is redColor. */
  112. @property (nonatomic, strong, readwrite) UIColor *charCountLabelWarningColor;
  113. @end
  114. NS_ASSUME_NONNULL_END