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 111f900..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. @@ -38,16 +39,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, strong, nonnull) IBInspectable UIFont *font; +@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..26e0182 100644 --- a/CBAutoScrollLabel/CBAutoScrollLabel.m +++ b/CBAutoScrollLabel/CBAutoScrollLabel.m @@ -62,7 +62,7 @@ - (void)commonInit { UILabel *label = [[UILabel alloc] init]; label.backgroundColor = [UIColor clearColor]; label.autoresizingMask = self.autoresizingMask; - + // store labels [self.scrollView addSubview:label]; [labelSet addObject:label]; @@ -75,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; @@ -91,6 +95,12 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } +- (void)prepareForInterfaceBuilder { + [super prepareForInterfaceBuilder]; + + self.text = @"AutoScrollLabel"; +} + - (void)setFrame:(CGRect)frame { [super setFrame:frame]; @@ -198,7 +208,7 @@ - (UIFont *)font { return self.mainLabel.font; } -- (void)setScrollSpeed:(float)speed { +- (void)setScrollSpeed:(CGFloat)speed { _scrollSpeed = speed; [self scrollLabelIfNeeded];