From fa6fb4d4716a42299086e27bc942dd25dc60d649 Mon Sep 17 00:00:00 2001 From: tingxins Date: Thu, 24 Nov 2016 01:08:33 +0800 Subject: [PATCH] add TXScrollLabelViewDelegate Methods. --- TXScrollLabelView/TXScrollLabelView.h | 9 +++++++++ TXScrollLabelView/TXScrollLabelView.m | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/TXScrollLabelView/TXScrollLabelView.h b/TXScrollLabelView/TXScrollLabelView.h index b0b6d2b..98f34ed 100644 --- a/TXScrollLabelView/TXScrollLabelView.h +++ b/TXScrollLabelView/TXScrollLabelView.h @@ -11,6 +11,14 @@ #import #import "UIView+TXFrame.h" +@class TXScrollLabelView; + +@protocol TXScrollLabelViewDelegate +@optional +- (void)scrollLabelView:(TXScrollLabelView *)scrollLabelView didClickWithText:(NSString *)text; + +@end + @interface TXScrollLabelView : UIScrollView typedef NS_ENUM(NSInteger, TXScrollLabelViewType) { @@ -35,6 +43,7 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) { /*************ALL ABOVE.***********************************/ #pragma mark - On Used Property +@property (weak, nonatomic) id scrollLabelViewDelegate; /** 滚动文字 */ @property (copy, nonatomic) NSString *scrollTitle; /** 滚动类型 */ diff --git a/TXScrollLabelView/TXScrollLabelView.m b/TXScrollLabelView/TXScrollLabelView.m index 37418a1..d7b12bb 100644 --- a/TXScrollLabelView/TXScrollLabelView.m +++ b/TXScrollLabelView/TXScrollLabelView.m @@ -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]; @@ -141,6 +154,8 @@ - (instancetype)initWithFrame:(CGRect)frame { [self setSomePreference]; [self setSomeSubviews]; + + [self setTapGesture]; } return self; }