Skip to content

Commit

Permalink
add TXScrollLabelViewDelegate Methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
tingxins committed Nov 23, 2016
1 parent 19d20f2 commit fa6fb4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions TXScrollLabelView/TXScrollLabelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
#import <UIKit/UIKit.h>
#import "UIView+TXFrame.h"

@class TXScrollLabelView;

@protocol TXScrollLabelViewDelegate <NSObject>
@optional
- (void)scrollLabelView:(TXScrollLabelView *)scrollLabelView didClickWithText:(NSString *)text;

@end

@interface TXScrollLabelView : UIScrollView

typedef NS_ENUM(NSInteger, TXScrollLabelViewType) {
Expand All @@ -35,6 +43,7 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) {
/*************ALL ABOVE.***********************************/

#pragma mark - On Used Property
@property (weak, nonatomic) id<TXScrollLabelViewDelegate> scrollLabelViewDelegate;
/** 滚动文字 */
@property (copy, nonatomic) NSString *scrollTitle;
/** 滚动类型 */
Expand Down
17 changes: 16 additions & 1 deletion TXScrollLabelView/TXScrollLabelView.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ - (void)setSomeSubviews {
[self addSubview:downLabel];
}

#pragma mark - init Methods
- (void)setTapGesture {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap)];
[self addGestureRecognizer:tapGesture];
}

#pragma mark - Target Methods

- (void)didTap {
if ([self.scrollLabelViewDelegate respondsToSelector:@selector(scrollLabelView:didClickWithText:)]) {
[self.scrollLabelViewDelegate scrollLabelView:self didClickWithText:_scrollTitle];
}
}

#pragma mark - Init Methods
/** 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 - scrollWithTitle:scrollType:scrollVelocity:options:" userInfo:nil];
Expand All @@ -141,6 +154,8 @@ - (instancetype)initWithFrame:(CGRect)frame {
[self setSomePreference];

[self setSomeSubviews];

[self setTapGesture];
}
return self;
}
Expand Down

0 comments on commit fa6fb4d

Please sign in to comment.