123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // TXScrollLabelView.h
- //
- // Created by tingxins on 2/23/16.
- // Copyright © 2016 tingxins. All rights reserved.
- // 如果在使用 TXScrollLabelView 的过程中出现bug,请及时联系,我会尽快进行修复。如果有更好的点子,直接 Open an issue 或者 submit a pr。
- /**
- Blog : https://tingxins.com
- 简书 :http://www.jianshu.com/u/5141561e4d59
- GitHub : https://github.com/tingxins
- Weibo : http://weibo.com/tingxins
- Twitter : http://twitter.com/tingxins
- */
- #define TX_DEPRECATED_METHODS(explain) __attribute__((deprecated(explain)))
- #define TX_DEPRECATED_MESSAGES(explain) __deprecated_msg(explain)
- #import <UIKit/UIKit.h>
- #import "UIView+TXFrame.h"
- @class TXScrollLabelView;
- @protocol TXScrollLabelViewDelegate <NSObject>
- @optional
- - (void)scrollLabelView:(TXScrollLabelView *)scrollLabelView didClickWithText:(NSString *)text atIndex:(NSInteger)index;
- @end
- @interface TXScrollLabelView : UIScrollView
- typedef NS_ENUM(NSInteger, TXScrollLabelViewType) {
- TXScrollLabelViewTypeLeftRight = 0, //not supports scrollInset.top\bottom\right
- TXScrollLabelViewTypeUpDown, //not supports scrollInset.top\bottom
- TXScrollLabelViewTypeFlipRepeat, //not supports scrollInset.top\bottom
- TXScrollLabelViewTypeFlipNoRepeat //not supports scrollInset.top\bottom
- };
- /*************WILL BE REMOVED IN FUTURE.********************/
- #pragma mark - Deprecated property
- /** Deprecated, please Use `scrollTitle` */
- @property (copy, nonatomic) NSString *tx_scrollTitle TX_DEPRECATED_METHODS("Deprecated, please Use `scrollTitle`");
- /** Deprecated, please Use `scrollType` */
- @property (assign, nonatomic) TXScrollLabelViewType tx_scrollType TX_DEPRECATED_METHODS("Deprecated, please Use `scrollType`");
- /** Deprecated, please Use `scrollVelocity` */
- @property (assign, nonatomic) NSTimeInterval tx_scrollVelocity TX_DEPRECATED_METHODS("Deprecated, please Use `scrollVelocity`");
- /** Deprecated, please Use `frame` */
- @property (assign, nonatomic) CGRect tx_scrollContentSize TX_DEPRECATED_METHODS("Deprecated, please Use `frame`");
- /** Deprecated, please Use `scrollTitleColor` */
- @property (strong, nonatomic) UIColor *tx_scrollTitleColor TX_DEPRECATED_METHODS("Deprecated, please Use `scrollTitleColor`");
- /*************ALL ABOVE.***********************************/
- #pragma mark - On Used Property
- @property (weak, nonatomic) id<TXScrollLabelViewDelegate> scrollLabelViewDelegate;
- /** 滚动文字 */
- @property (copy, nonatomic) NSString *scrollTitle;
- /** 滚动类型 */
- @property (assign, nonatomic) TXScrollLabelViewType scrollType;
- /** 滚动速率([0, 10]),单位秒s,建议在初始化方法中设置该属性*/
- @property (assign, nonatomic) NSTimeInterval scrollVelocity;
- /** 文本颜色 */
- @property (strong, nonatomic) UIColor *scrollTitleColor;
- /** 滚动内部inset */
- @property (assign, nonatomic) UIEdgeInsets scrollInset;
- /** 每次循环滚动的间距 */
- @property (assign, nonatomic) CGFloat scrollSpace;
- /** 文字排版 */
- @property (assign, nonatomic) NSTextAlignment textAlignment;
- /** 字体大小 */
- @property (strong, nonatomic) UIFont *font;
- //根据内容自适应宽度 Pending!!
- @property (assign, nonatomic) BOOL autoWidth;
- #pragma mark - setupAttributeTitle
- - (void)setupAttributeTitle:(NSAttributedString *)attributeTitle;
- #pragma mark - Instance Methods
- - (instancetype)initWithTitle:(NSString *)scrollTitle
- type:(TXScrollLabelViewType)scrollType
- velocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options
- inset:(UIEdgeInsets)inset;
- #pragma mark - Factory Methods
- + (instancetype)scrollWithTitle:(NSString *)scrollTitle;
- + (instancetype)scrollWithTitle:(NSString *)scrollTitle
- type:(TXScrollLabelViewType)scrollType;
- + (instancetype)scrollWithTitle:(NSString *)scrollTitle
- type:(TXScrollLabelViewType)scrollType
- velocity:(NSTimeInterval)scrollVelocity;
- + (instancetype)scrollWithTitle:(NSString *)scrollTitle
- type:(TXScrollLabelViewType)scrollType
- velocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options;
- /**
- 类初始化方法
- @param scrollTitle 滚动文本
- @param scrollType 滚动类型
- @param scrollVelocity 滚动速率
- @param options Now, supports the types of TXScrollLabelViewTypeFlipRepeat\NoRepeat only.
- @param inset just edgeInset.
- */
- + (instancetype)scrollWithTitle:(NSString *)scrollTitle
- type:(TXScrollLabelViewType)scrollType
- velocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options
- inset:(UIEdgeInsets)inset;
- #pragma mark - Operation Methods
- /**
- * 开始滚动
- */
- - (void) beginScrolling;
- /**
- * 停止滚动
- */
- - (void) endScrolling;
- /**
- * 暂停滚动(暂不支持恢复)
- */
- - (void) pauseScrolling;
- @end
- @interface TXScrollLabelView (TXArray)
- /**
- 类初始化方法
- @param scrollTexts 滚动文本数组
- */
- - (instancetype)initWithTextArray:(NSArray *)scrollTexts
- type:(TXScrollLabelViewType)scrollType
- velocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options
- inset:(UIEdgeInsets)inset;
- + (instancetype)scrollWithTextArray:(NSArray *)scrollTexts
- type:(TXScrollLabelViewType)scrollType
- velocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options
- inset:(UIEdgeInsets)inset;
- @end
- @interface TXScrollLabelView (TXScrollLabelViewDeprecated)
- + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:`");
- + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
- scrollType:(TXScrollLabelViewType)scrollType TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:`");
- + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
- scrollType:(TXScrollLabelViewType)scrollType
- scrollVelocity:(NSTimeInterval)scrollVelocity TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:velocity:`");
- + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
- scrollType:(TXScrollLabelViewType)scrollType
- scrollVelocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:velocity:options:`");
- + (instancetype)tx_setScrollTitle:(NSString *)scrollTitle
- scrollType:(TXScrollLabelViewType)scrollType
- scrollVelocity:(NSTimeInterval)scrollVelocity
- options:(UIViewAnimationOptions)options
- inset:(UIEdgeInsets)inset TX_DEPRECATED_MESSAGES("Method deprecated. Use `+ scrollWithTitle:type:velocity:options:inset:`");
- @end
- @interface UIView (TXAdditions)
- - (void)addTapGesture:(id)target sel:(SEL)selector;
- @end
|