From ecb5ce998af66ef09e23517c81fcc090f7bdb2a7 Mon Sep 17 00:00:00 2001 From: tingxins Date: Sun, 20 Nov 2016 11:58:17 +0800 Subject: [PATCH] Refactored some duplicate methods from our TXScrollLabelView to TXScrollLabelViewDeprecated category. --- TXScrollLabelView/TXScrollLabelView.h | 77 +++++++++------ TXScrollLabelView/TXScrollLabelView.m | 129 ++++++++++++++++++-------- 2 files changed, 140 insertions(+), 66 deletions(-) diff --git a/TXScrollLabelView/TXScrollLabelView.h b/TXScrollLabelView/TXScrollLabelView.h index 72d687f..b0b6d2b 100644 --- a/TXScrollLabelView/TXScrollLabelView.h +++ b/TXScrollLabelView/TXScrollLabelView.h @@ -5,7 +5,8 @@ // Copyright © 2016 tingxins. All rights reserved. // 滚动视图 -#define TX_DEPRECATED(explain) __attribute__((deprecated(explain))) +#define TX_DEPRECATED_METHODS(explain) __attribute__((deprecated(explain))) +#define TX_DEPRECATED_MESSAGES(explain) __deprecated_msg(explain) #import #import "UIView+TXFrame.h" @@ -20,17 +21,17 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) { }; /*************WILL BE REMOVED IN FUTURE.********************/ -#pragma mark - Deprecated Property +#pragma mark - Deprecated property /** Deprecated, please Use `scrollTitle` */ -@property (copy, nonatomic) NSString *tx_scrollTitle TX_DEPRECATED("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("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("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("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("Deprecated, please Use `scrollTitleColor`"); +@property (strong, nonatomic) UIColor *tx_scrollTitleColor TX_DEPRECATED_METHODS("Deprecated, please Use `scrollTitleColor`"); /*************ALL ABOVE.***********************************/ #pragma mark - On Used Property @@ -57,25 +58,24 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) { #pragma mark - Class Methods - (instancetype)initWithTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity - options:(UIViewAnimationOptions)options - inset:(UIEdgeInsets)inset; + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options + inset:(UIEdgeInsets)inset; -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle; ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle; -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType; - -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity; ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType; -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity - options:(UIViewAnimationOptions)options; ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity; ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options; /** 类初始化方法 @@ -85,11 +85,11 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) { @param options Now, supports the types of TXScrollLabelViewTypeFlipRepeat\NoRepeat only. @param inset just edgeInset. */ -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity - options:(UIViewAnimationOptions)options - inset:(UIEdgeInsets)inset; ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options + inset:(UIEdgeInsets)inset; #pragma mark - Operation Methods /** @@ -107,3 +107,26 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) { - (void) pauseScrolling; @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 diff --git a/TXScrollLabelView/TXScrollLabelView.m b/TXScrollLabelView/TXScrollLabelView.m index 47214c6..a602bb6 100644 --- a/TXScrollLabelView/TXScrollLabelView.m +++ b/TXScrollLabelView/TXScrollLabelView.m @@ -130,9 +130,9 @@ - (void)setSomeSubviews { } #pragma mark - init Methods -/** Terminating app due to uncaught exception 'Warning TXScrollLabelView -[TXScrollLabelView init] unimplemented!', reason: 'unimplemented, use - tx_setScrollTitle:scrollType:scrollVelocity:options:'*/ +/** Terminating app due to uncaught exception 'Warning TXScrollLabelView -[TXScrollLabelView init] unimplemented!', reason: 'unimplemented, use - scrollWithTitle:scrollType:scrollVelocity:options:'*/ - (instancetype)init { - @throw [NSException exceptionWithName:[NSString stringWithFormat:@"Warning %@ %s unimplemented!", self.class, __func__] reason:@"unimplemented, please use - tx_setScrollTitle:scrollType:scrollVelocity:options:" userInfo:nil]; + @throw [NSException exceptionWithName:[NSString stringWithFormat:@"Warning %@ %s unimplemented!", self.class, __func__] reason:@"unimplemented, please use - scrollWithTitle:scrollType:scrollVelocity:options:" userInfo:nil]; } - (instancetype)initWithFrame:(CGRect)frame { @@ -146,10 +146,10 @@ - (instancetype)initWithFrame:(CGRect)frame { } - (instancetype)initWithTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity - options:(UIViewAnimationOptions)options - inset:(UIEdgeInsets)inset { + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options + inset:(UIEdgeInsets)inset { if (self = [super init]) { self.scrollTitle = scrollTitle; self.scrollType = scrollType; @@ -160,51 +160,53 @@ - (instancetype)initWithTitle:(NSString *)scrollTitle return self; } -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle { ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle { - return [self tx_setScrollTitle:scrollTitle - scrollType:TXScrollLabelViewTypeLeftRight]; + return [self scrollWithTitle:scrollTitle + type:TXScrollLabelViewTypeLeftRight]; } -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType { ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType { - return [self tx_setScrollTitle:scrollTitle - scrollType:scrollType - scrollVelocity:TXScrollDefaultTimeInterval]; + return [self scrollWithTitle:scrollTitle + type:scrollType + velocity:TXScrollDefaultTimeInterval]; } -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity { ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity { - return [self tx_setScrollTitle:scrollTitle - scrollType:scrollType - scrollVelocity:scrollVelocity - options:UIViewAnimationOptionCurveEaseInOut]; + return [self scrollWithTitle:scrollTitle + type:scrollType + velocity:scrollVelocity + options:UIViewAnimationOptionCurveEaseInOut]; } -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity - options:(UIViewAnimationOptions)options { ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options { - return [self tx_setScrollTitle:scrollTitle - scrollType:scrollType - scrollVelocity:scrollVelocity - options:options inset:UIEdgeInsetsMake(0, 5, 0, 5)]; -} - -+ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle - scrollType:(TXScrollLabelViewType)scrollType - scrollVelocity:(NSTimeInterval)scrollVelocity - options:(UIViewAnimationOptions)options - inset:(UIEdgeInsets)inset { + return [self scrollWithTitle:scrollTitle + type:scrollType + velocity:scrollVelocity + options:options + inset:UIEdgeInsetsMake(0, 5, 0, 5)]; +} + ++ (instancetype)scrollWithTitle:(NSString *)scrollTitle + type:(TXScrollLabelViewType)scrollType + velocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options + inset:(UIEdgeInsets)inset { return [[self alloc] initWithTitle:scrollTitle - scrollType:scrollType - scrollVelocity:scrollVelocity - options:options inset:inset]; + type:scrollType + velocity:scrollVelocity + options:options + inset:inset]; } #pragma mark - Getter & Setter Methods @@ -511,3 +513,52 @@ - (void)dealloc { } @end + +@implementation TXScrollLabelView (TXScrollLabelViewDeprecated) + ++ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle { + + return [self scrollWithTitle:scrollTitle]; +} + ++ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle + scrollType:(TXScrollLabelViewType)scrollType { + + return [self scrollWithTitle:scrollTitle + type:scrollType]; +} + ++ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle + scrollType:(TXScrollLabelViewType)scrollType + scrollVelocity:(NSTimeInterval)scrollVelocity { + + return [self scrollWithTitle:scrollTitle + type:scrollType + velocity:scrollVelocity]; +} + ++ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle + scrollType:(TXScrollLabelViewType)scrollType + scrollVelocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options { + + return [self scrollWithTitle:scrollTitle + type:scrollType + velocity:scrollVelocity + options:options]; +} + ++ (instancetype)tx_setScrollTitle:(NSString *)scrollTitle + scrollType:(TXScrollLabelViewType)scrollType + scrollVelocity:(NSTimeInterval)scrollVelocity + options:(UIViewAnimationOptions)options + inset:(UIEdgeInsets)inset { + + return [self scrollWithTitle:scrollTitle + type:scrollType + velocity:scrollVelocity + options:options + inset:inset]; +} + +@end