YYTextInput.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // YYTextInput.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/4/17.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. Text position affinity. For example, the offset appears after the last
  15. character on a line is backward affinity, before the first character on
  16. the following line is forward affinity.
  17. */
  18. typedef NS_ENUM(NSInteger, YYTextAffinity) {
  19. YYTextAffinityForward = 0, ///< offset appears before the character
  20. YYTextAffinityBackward = 1, ///< offset appears after the character
  21. };
  22. /**
  23. A YYTextPosition object represents a position in a text container; in other words,
  24. it is an index into the backing string in a text-displaying view.
  25. YYTextPosition has the same API as Apple's implementation in UITextView/UITextField,
  26. so you can alse use it to interact with UITextView/UITextField.
  27. */
  28. @interface YYTextPosition : UITextPosition <NSCopying>
  29. @property (nonatomic, readonly) NSInteger offset;
  30. @property (nonatomic, readonly) YYTextAffinity affinity;
  31. + (instancetype)positionWithOffset:(NSInteger)offset;
  32. + (instancetype)positionWithOffset:(NSInteger)offset affinity:(YYTextAffinity) affinity;
  33. - (NSComparisonResult)compare:(id)otherPosition;
  34. @end
  35. /**
  36. A YYTextRange object represents a range of characters in a text container; in other words,
  37. it identifies a starting index and an ending index in string backing a text-displaying view.
  38. YYTextRange has the same API as Apple's implementation in UITextView/UITextField,
  39. so you can alse use it to interact with UITextView/UITextField.
  40. */
  41. @interface YYTextRange : UITextRange <NSCopying>
  42. @property (nonatomic, readonly) YYTextPosition *start;
  43. @property (nonatomic, readonly) YYTextPosition *end;
  44. @property (nonatomic, readonly, getter=isEmpty) BOOL empty;
  45. + (instancetype)rangeWithRange:(NSRange)range;
  46. + (instancetype)rangeWithRange:(NSRange)range affinity:(YYTextAffinity) affinity;
  47. + (instancetype)rangeWithStart:(YYTextPosition *)start end:(YYTextPosition *)end;
  48. + (instancetype)defaultRange; ///< <{0,0} Forward>
  49. - (NSRange)asRange;
  50. @end
  51. /**
  52. A YYTextSelectionRect object encapsulates information about a selected range of
  53. text in a text-displaying view.
  54. YYTextSelectionRect has the same API as Apple's implementation in UITextView/UITextField,
  55. so you can alse use it to interact with UITextView/UITextField.
  56. */
  57. @interface YYTextSelectionRect : UITextSelectionRect <NSCopying>
  58. @property (nonatomic, readwrite) CGRect rect;
  59. @property (nonatomic, readwrite) UITextWritingDirection writingDirection;
  60. @property (nonatomic, readwrite) BOOL containsStart;
  61. @property (nonatomic, readwrite) BOOL containsEnd;
  62. @property (nonatomic, readwrite) BOOL isVertical;
  63. @end
  64. NS_ASSUME_NONNULL_END