Skip to content

Commit

Permalink
Refactored some duplicate methods from our TXScrollLabelView to TXScr…
Browse files Browse the repository at this point in the history
…ollLabelViewDeprecated category.
  • Loading branch information
tingxins committed Nov 20, 2016
1 parent 784501f commit ecb5ce9
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 66 deletions.
77 changes: 50 additions & 27 deletions TXScrollLabelView/TXScrollLabelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <UIKit/UIKit.h>
#import "UIView+TXFrame.h"
Expand All @@ -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
Expand All @@ -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;

/**
类初始化方法
Expand All @@ -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
/**
Expand All @@ -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
129 changes: 90 additions & 39 deletions TXScrollLabelView/TXScrollLabelView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit ecb5ce9

Please sign in to comment.