YYTextRunDelegate.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // YYTextRunDelegate.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 14/10/14.
  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. #import <CoreText/CoreText.h>
  13. NS_ASSUME_NONNULL_BEGIN
  14. /**
  15. Wrapper for CTRunDelegateRef.
  16. Example:
  17. YYTextRunDelegate *delegate = [YYTextRunDelegate new];
  18. delegate.ascent = 20;
  19. delegate.descent = 4;
  20. delegate.width = 20;
  21. CTRunDelegateRef ctRunDelegate = delegate.CTRunDelegate;
  22. if (ctRunDelegate) {
  23. /// add to attributed string
  24. CFRelease(ctRunDelegate);
  25. }
  26. */
  27. @interface YYTextRunDelegate : NSObject <NSCopying, NSCoding>
  28. /**
  29. Creates and returns the CTRunDelegate.
  30. @discussion You need call CFRelease() after used.
  31. The CTRunDelegateRef has a strong reference to this YYTextRunDelegate object.
  32. In CoreText, use CTRunDelegateGetRefCon() to get this YYTextRunDelegate object.
  33. @return The CTRunDelegate object.
  34. */
  35. - (nullable CTRunDelegateRef)CTRunDelegate CF_RETURNS_RETAINED;
  36. /**
  37. Additional information about the the run delegate.
  38. */
  39. @property (nullable, nonatomic, strong) NSDictionary *userInfo;
  40. /**
  41. The typographic ascent of glyphs in the run.
  42. */
  43. @property (nonatomic) CGFloat ascent;
  44. /**
  45. The typographic descent of glyphs in the run.
  46. */
  47. @property (nonatomic) CGFloat descent;
  48. /**
  49. The typographic width of glyphs in the run.
  50. */
  51. @property (nonatomic) CGFloat width;
  52. @end
  53. NS_ASSUME_NONNULL_END