TXScrollLabelView.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // TXScrollLabelView.h
  3. //
  4. // Created by tingxins on 2/23/16.
  5. // Copyright © 2016 tingxins. All rights reserved.
  6. // 如果在使用 TXScrollLabelView 的过程中出现bug,请及时联系,我会尽快进行修复。如果有更好的点子,直接 Open an issue 或者 submit a pr。
  7. /**
  8. Blog : https://tingxins.com
  9. 简书 :http://www.jianshu.com/u/5141561e4d59
  10. GitHub : https://github.com/tingxins
  11. Weibo : http://weibo.com/tingxins
  12. Twitter : http://twitter.com/tingxins
  13. */
  14. #define TX_DEPRECATED_METHODS(explain) __attribute__((deprecated(explain)))
  15. #define TX_DEPRECATED_MESSAGES(explain) __deprecated_msg(explain)
  16. #import <UIKit/UIKit.h>
  17. #import "UIView+TXFrame.h"
  18. @class TXScrollLabelView;
  19. @protocol TXScrollLabelViewDelegate <NSObject>
  20. @optional
  21. - (void)scrollLabelView:(TXScrollLabelView *)scrollLabelView didClickWithText:(NSString *)text atIndex:(NSInteger)index;
  22. @end
  23. @interface TXScrollLabelView : UIScrollView
  24. typedef NS_ENUM(NSInteger, TXScrollLabelViewType) {
  25. TXScrollLabelViewTypeLeftRight = 0, //not supports scrollInset.top\bottom\right
  26. TXScrollLabelViewTypeUpDown, //not supports scrollInset.top\bottom
  27. TXScrollLabelViewTypeFlipRepeat, //not supports scrollInset.top\bottom
  28. TXScrollLabelViewTypeFlipNoRepeat //not supports scrollInset.top\bottom
  29. };
  30. /*************WILL BE REMOVED IN FUTURE.********************/
  31. #pragma mark - Deprecated property
  32. /** Deprecated, please Use `scrollTitle` */
  33. @property (copy, nonatomic) NSString *tx_scrollTitle TX_DEPRECATED_METHODS("Deprecated, please Use `scrollTitle`");
  34. /** Deprecated, please Use `scrollType` */
  35. @property (assign, nonatomic) TXScrollLabelViewType tx_scrollType TX_DEPRECATED_METHODS("Deprecated, please Use `scrollType`");
  36. /** Deprecated, please Use `scrollVelocity` */
  37. @property (assign, nonatomic) NSTimeInterval tx_scrollVelocity TX_DEPRECATED_METHODS("Deprecated, please Use `scrollVelocity`");
  38. /** Deprecated, please Use `frame` */
  39. @property (assign, nonatomic) CGRect tx_scrollContentSize TX_DEPRECATED_METHODS("Deprecated, please Use `frame`");
  40. /** Deprecated, please Use `scrollTitleColor` */
  41. @property (strong, nonatomic) UIColor *tx_scrollTitleColor TX_DEPRECATED_METHODS("Deprecated, please Use `scrollTitleColor`");
  42. /*************ALL ABOVE.***********************************/
  43. #pragma mark - On Used Property
  44. @property (weak, nonatomic) id<TXScrollLabelViewDelegate> scrollLabelViewDelegate;
  45. /** 滚动文字 */
  46. @property (copy, nonatomic) NSString *scrollTitle;
  47. /** 滚动类型 */
  48. @property (assign, nonatomic) TXScrollLabelViewType scrollType;
  49. /** 滚动速率([0, 10]),单位秒s,建议在初始化方法中设置该属性*/
  50. @property (assign, nonatomic) NSTimeInterval scrollVelocity;
  51. /** 文本颜色 */
  52. @property (strong, nonatomic) UIColor *scrollTitleColor;
  53. /** 滚动内部inset */
  54. @property (assign, nonatomic) UIEdgeInsets scrollInset;
  55. /** 每次循环滚动的间距 */
  56. @property (assign, nonatomic) CGFloat scrollSpace;
  57. /** 文字排版 */
  58. @property (assign, nonatomic) NSTextAlignment textAlignment;
  59. /** 字体大小 */
  60. @property (strong, nonatomic) UIFont *font;
  61. //根据内容自适应宽度 Pending!!
  62. @property (assign, nonatomic) BOOL autoWidth;
  63. #pragma mark - setupAttributeTitle
  64. - (void)setupAttributeTitle:(NSAttributedString *)attributeTitle;
  65. #pragma mark - Instance Methods
  66. - (instancetype)initWithTitle:(NSString *)scrollTitle
  67. type:(TXScrollLabelViewType)scrollType
  68. velocity:(NSTimeInterval)scrollVelocity
  69. options:(UIViewAnimationOptions)options
  70. inset:(UIEdgeInsets)inset;
  71. #pragma mark - Factory Methods
  72. + (instancetype)scrollWithTitle:(NSString *)scrollTitle;
  73. + (instancetype)scrollWithTitle:(NSString *)scrollTitle
  74. type:(TXScrollLabelViewType)scrollType;
  75. + (instancetype)scrollWithTitle:(NSString *)scrollTitle
  76. type:(TXScrollLabelViewType)scrollType
  77. velocity:(NSTimeInterval)scrollVelocity;
  78. + (instancetype)scrollWithTitle:(NSString *)scrollTitle
  79. type:(TXScrollLabelViewType)scrollType
  80. velocity:(NSTimeInterval)scrollVelocity
  81. options:(UIViewAnimationOptions)options;
  82. /**
  83. 类初始化方法
  84. @param scrollTitle 滚动文本
  85. @param scrollType 滚动类型
  86. @param scrollVelocity 滚动速率
  87. @param options Now, supports the types of TXScrollLabelViewTypeFlipRepeat\NoRepeat only.
  88. @param inset just edgeInset.
  89. */
  90. + (instancetype)scrollWithTitle:(NSString *)scrollTitle
  91. type:(TXScrollLabelViewType)scrollType
  92. velocity:(NSTimeInterval)scrollVelocity
  93. options:(UIViewAnimationOptions)options
  94. inset:(UIEdgeInsets)inset;
  95. #pragma mark - Operation Methods
  96. /**
  97. * 开始滚动
  98. */
  99. - (void) beginScrolling;
  100. /**
  101. * 停止滚动
  102. */
  103. - (void) endScrolling;
  104. /**
  105. * 暂停滚动(暂不支持恢复)
  106. */
  107. - (void) pauseScrolling;
  108. @end
  109. @interface TXScrollLabelView (TXArray)
  110. /**
  111. 类初始化方法
  112. @param scrollTexts 滚动文本数组
  113. */
  114. - (instancetype)initWithTextArray:(NSArray *)scrollTexts
  115. type:(TXScrollLabelViewType)scrollType
  116. velocity:(NSTimeInterval)scrollVelocity
  117. options:(UIViewAnimationOptions)options
  118. inset:(UIEdgeInsets)inset;
  119. + (instancetype)scrollWithTextArray:(NSArray *)scrollTexts
  120. type:(TXScrollLabelViewType)scrollType
  121. velocity:(NSTimeInterval)scrollVelocity
  122. options:(UIViewAnimationOptions)options
  123. inset:(UIEdgeInsets)inset;
  124. @end
  125. @interface TXScrollLabelView (TXScrollLabelViewDeprecated)
  126. + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:`");
  127. + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
  128. scrollType:(TXScrollLabelViewType)scrollType TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:`");
  129. + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
  130. scrollType:(TXScrollLabelViewType)scrollType
  131. scrollVelocity:(NSTimeInterval)scrollVelocity TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:velocity:`");
  132. + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
  133. scrollType:(TXScrollLabelViewType)scrollType
  134. scrollVelocity:(NSTimeInterval)scrollVelocity
  135. options:(UIViewAnimationOptions)options TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:velocity:options:`");
  136. + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
  137. scrollType:(TXScrollLabelViewType)scrollType
  138. scrollVelocity:(NSTimeInterval)scrollVelocity
  139. options:(UIViewAnimationOptions)options
  140. inset:(UIEdgeInsets)inset TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:velocity:options:inset:`");
  141. @end
  142. @interface UIView (TXAdditions)
  143. - (void)addTapGesture:(id)target sel:(SEL)selector;
  144. @end