From b6656a04ed6837a1b74ab15a08b1ff92c9e68f0a Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Sat, 21 Sep 2019 02:31:26 +0800 Subject: [PATCH 1/2] IB_DESIGNABLE Support (#57) IB_DESIGNABLE Support. Label, Text Color and Text Shadow Color can be customized using the storyboard. --- CBAutoScrollLabel/CBAutoScrollLabel.h | 11 ++++++----- CBAutoScrollLabel/CBAutoScrollLabel.m | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CBAutoScrollLabel/CBAutoScrollLabel.h b/CBAutoScrollLabel/CBAutoScrollLabel.h index 111f900..a6e858a 100644 --- a/CBAutoScrollLabel/CBAutoScrollLabel.h +++ b/CBAutoScrollLabel/CBAutoScrollLabel.h @@ -38,16 +38,17 @@ typedef NS_ENUM(NSInteger, CBAutoScrollDirection) { * Returns YES, if it is actively scrolling, NO if it has paused or if text is within bounds (disables scrolling). */ @property (nonatomic, readonly) BOOL scrolling; -@property (nonatomic) CGFloat fadeLength; // defaults to 7 +@property (nonatomic) IBInspectable CGFloat fadeLength; // defaults to 7 // UILabel properties @property (nonatomic, strong, nonnull) UIFont *font; -@property (nonatomic, copy, nullable) NSString *text; +@property (nonatomic, copy, nullable) IBInspectable NSString *text; @property (nonatomic, copy, nullable) NSAttributedString *attributedText; -@property (nonatomic, strong, nonnull) UIColor *textColor; +@property (nonatomic, strong, nonnull) IBInspectable UIColor *textColor; @property (nonatomic) NSTextAlignment textAlignment; // only applies when not auto-scrolling -@property (nonatomic, strong, nullable) UIColor *shadowColor; -@property (nonatomic) CGSize shadowOffset; +@property (nonatomic, strong, nullable) IBInspectable UIColor *shadowColor; + +@property (nonatomic) IBInspectable CGSize shadowOffset; /** * Lays out the scrollview contents, enabling text scrolling if the text will be clipped. diff --git a/CBAutoScrollLabel/CBAutoScrollLabel.m b/CBAutoScrollLabel/CBAutoScrollLabel.m index 837e05a..d98cec8 100644 --- a/CBAutoScrollLabel/CBAutoScrollLabel.m +++ b/CBAutoScrollLabel/CBAutoScrollLabel.m @@ -38,6 +38,7 @@ @interface CBAutoScrollLabel () @end +IB_DESIGNABLE @implementation CBAutoScrollLabel - (id)initWithCoder:(NSCoder *)aDecoder { @@ -62,7 +63,8 @@ - (void)commonInit { UILabel *label = [[UILabel alloc] init]; label.backgroundColor = [UIColor clearColor]; label.autoresizingMask = self.autoresizingMask; - + // Placeholder text for IB_DESIGNABLE in Storyboards + label.text = @"AutoScrollLabel"; // store labels [self.scrollView addSubview:label]; [labelSet addObject:label]; From 4a9f152c337e9f5d98ce2cfccd4e67af3deb55ae Mon Sep 17 00:00:00 2001 From: "C. Bess" Date: Fri, 20 Sep 2019 14:27:39 -0500 Subject: [PATCH 2/2] add IB designer support --- .../Base.lproj/Main.storyboard | 2 +- CBAutoScrollLabel/CBAutoScrollLabel.h | 7 ++++--- CBAutoScrollLabel/CBAutoScrollLabel.m | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/AutoScrollLabelDemo/AutoScrollLabelDemo/Base.lproj/Main.storyboard b/AutoScrollLabelDemo/AutoScrollLabelDemo/Base.lproj/Main.storyboard index 0a67842..b5ff080 100644 --- a/AutoScrollLabelDemo/AutoScrollLabelDemo/Base.lproj/Main.storyboard +++ b/AutoScrollLabelDemo/AutoScrollLabelDemo/Base.lproj/Main.storyboard @@ -47,7 +47,7 @@ - + diff --git a/CBAutoScrollLabel/CBAutoScrollLabel.h b/CBAutoScrollLabel/CBAutoScrollLabel.h index a6e858a..d1310fb 100644 --- a/CBAutoScrollLabel/CBAutoScrollLabel.h +++ b/CBAutoScrollLabel/CBAutoScrollLabel.h @@ -20,13 +20,14 @@ typedef NS_ENUM(NSInteger, CBAutoScrollDirection) { CBAutoScrollDirectionLeft }; +IB_DESIGNABLE @interface CBAutoScrollLabel : UIView @property (nonatomic) CBAutoScrollDirection scrollDirection; /// Scroll speed in pixels per second, defaults to 30 -@property (nonatomic) float scrollSpeed; +@property (nonatomic) IBInspectable CGFloat scrollSpeed; @property (nonatomic) NSTimeInterval pauseInterval; // defaults to 1.5 -@property (nonatomic) NSInteger labelSpacing; // pixels, defaults to 20 +@property (nonatomic) IBInspectable NSInteger labelSpacing; // pixels, defaults to 20 /** * The animation options used when scrolling the UILabels. @@ -41,7 +42,7 @@ typedef NS_ENUM(NSInteger, CBAutoScrollDirection) { @property (nonatomic) IBInspectable CGFloat fadeLength; // defaults to 7 // UILabel properties -@property (nonatomic, strong, nonnull) UIFont *font; +@property (nonatomic, strong, nonnull) IBInspectable UIFont *font; @property (nonatomic, copy, nullable) IBInspectable NSString *text; @property (nonatomic, copy, nullable) NSAttributedString *attributedText; @property (nonatomic, strong, nonnull) IBInspectable UIColor *textColor; diff --git a/CBAutoScrollLabel/CBAutoScrollLabel.m b/CBAutoScrollLabel/CBAutoScrollLabel.m index d98cec8..26e0182 100644 --- a/CBAutoScrollLabel/CBAutoScrollLabel.m +++ b/CBAutoScrollLabel/CBAutoScrollLabel.m @@ -38,7 +38,6 @@ @interface CBAutoScrollLabel () @end -IB_DESIGNABLE @implementation CBAutoScrollLabel - (id)initWithCoder:(NSCoder *)aDecoder { @@ -63,8 +62,7 @@ - (void)commonInit { UILabel *label = [[UILabel alloc] init]; label.backgroundColor = [UIColor clearColor]; label.autoresizingMask = self.autoresizingMask; - // Placeholder text for IB_DESIGNABLE in Storyboards - label.text = @"AutoScrollLabel"; + // store labels [self.scrollView addSubview:label]; [labelSet addObject:label]; @@ -77,7 +75,11 @@ - (void)commonInit { _scrollSpeed = kDefaultPixelsPerSecond; self.pauseInterval = kDefaultPauseTime; self.labelSpacing = kDefaultLabelBufferSpace; +#if TARGET_INTERFACE_BUILDER + self.textAlignment = NSTextAlignmentCenter; +#else self.textAlignment = NSTextAlignmentLeft; +#endif self.animationOptions = UIViewAnimationOptionCurveLinear; self.scrollView.showsVerticalScrollIndicator = NO; self.scrollView.showsHorizontalScrollIndicator = NO; @@ -93,6 +95,12 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } +- (void)prepareForInterfaceBuilder { + [super prepareForInterfaceBuilder]; + + self.text = @"AutoScrollLabel"; +} + - (void)setFrame:(CGRect)frame { [super setFrame:frame]; @@ -200,7 +208,7 @@ - (UIFont *)font { return self.mainLabel.font; } -- (void)setScrollSpeed:(float)speed { +- (void)setScrollSpeed:(CGFloat)speed { _scrollSpeed = speed; [self scrollLabelIfNeeded];